PHP Looping – While Loops

November 12th, 2010 by aBisona 
Loops execute a block of code a specified number of times, or while a specified condition is true. PHP Loops Often when you write code, you want the same block of code to run over and over again in a row. Instead of adding several almost equal lines in a script we can use loops to perform a task like this. In PHP, we have the following looping statements: while - loops through a block of code...

PHP Arrays

November 12th, 2010 by aBisona 
An array stores multiple values in one single variable. What is an Array? A variable is a storage area holding a number or text. The problem is, a variable will hold only one value. An array is a special variable, which can store multiple values in one single variable. If you have a list of items (a list of car names, for example), storing the cars in single variables could look like this: $cars1=”Saab”; $cars2=”Volvo”; $cars3=”BMW”; However,...

PHP Switch Statement

November 12th, 2010 by aBisona 
Conditional statements are used to perform different actions based on different conditions. The PHP Switch Statement Use the switch statement to select one of many blocks of code to be executed. Syntax switch (n) { case label1: code to be executed if n=label1; break; case label2: code to be executed if n=label2; break; default: code to be executed if n is different from both label1 and label2; } This...

PHP If…Else Statements

November 12th, 2010 by aBisona 
Conditional statements are used to perform different actions based on different conditions. Conditional Statements Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this. In PHP we have the following conditional statements: if statement – use this statement to execute some code only if a specified...

PHP Operators

November 12th, 2010 by aBisona 
Operators are used to operate on values. PHP Operators This section lists the different operators used in PHP. Arithmetic Operators Operator Description Example Result + Addition x=2 x+2 4 - Subtraction x=2 5-x 3 * Multiplication x=4 x*5 20 / Division 15/5 5/2 3 2.5 % Modulus (division remainder) 5%2 10%8 10%2 1 2 0 ++ Increment x=5 x++ x=6 – Decrement x=5 x– x=4 Assignment Operators Operator Example Is...

PHP String Variables

November 12th, 2010 by aBisona 
A string variable is used to store and manipulate text. String Variables in PHP String variables are used for values that contains characters. In this chapter we are going to look at the most common functions and operators used to manipulate strings in PHP. After we create a string we can manipulate it. A string can be used directly in a function or it can be stored in a variable. Below, the PHP...

PHP Variables

November 12th, 2010 by aBisona 
A variable is used to store information. Variables in PHP Variables are used for storing values, like text strings, numbers or arrays. When a variable is declared, it can be used over and over again in your script. All variables in PHP start with a $ sign symbol. The correct way of declaring a variable in PHP: $var_name = value; New PHP programmers often forget the $ sign at the beginning of the...

PHP Syntax

November 12th, 2010 by aBisona 
PHP code is executed on the server, and the plain HTML result is sent to the browser. Basic PHP Syntax A PHP scripting block always starts with <?php and ends with ?>. A PHP scripting block can be placed anywhere in the document. On servers with shorthand support enabled you can start a scripting block with <? and end with ?>. For maximum compatibility, we recommend that you use the...

PHP Installation

November 12th, 2010 by aBisona 
What do you Need? If your server supports PHP you don’t need to do anything. Just create some .php files in your web directory, and the server will parse them for you. Because it is free, most web hosts offer PHP support. However, if your server does not support PHP, you must install PHP. Here is a link to a good tutorial from PHP.net on how to install PHP5: http://www.php.net/manual/en/install.php Download...

PHP Introduction

November 12th, 2010 by aBisona 
PHP is a server-side scripting language. What You Should Already Know Before you continue you should have a basic understanding of the following: HTML/XHTML JavaScript If you want to study these subjects first, find the tutorials on our Home page. What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server PHP...

PHP Tutorial

November 12th, 2010 by aBisona 
PHP is a powerful tool for making dynamic and interactive Web pages. PHP is the widely-used, free, and efficient alternative to competitors such as Microsoft’s ASP. In our PHP tutorial you will learn about PHP, and how to execute scripts on your server. Start learning PHP now! PHP Quiz Test Test your PHP skills at W3Schools! Start PHP Quiz! PHP References At W3Schools you will find complete...

var_dump or print_r inside a Smarty template

November 8th, 2010 by VarIncart 
While trying to debug why something wasn’t working, I needed to see what data had been assigned to a Smarty template but from within the template itself (I didn’t have time to try and work out where in the PHP code the stuff was assigned and debug from there). This post shows how to do a var_dump or print_r from within the Smarty template itself. Using {$var|print_r} It is possible to...