Saturday, September 13, 2008
The chop() function
Sunday, September 7, 2008
The print Function
Syntax: print variablename;
Example inputs:
1.
print “smith”;
2.
$name = “Jones”;
print $name;
3.
$name=”Natasha”;
print “My name is $name”;
print “
”
print “What is yours?”;
Example outputs:
1.
Smith
2.
Jones
3.
My name is Natasha
What is yours?
Friday, September 5, 2008
Some PHP Exercises
What are the rules for naming a PHP variable?
Can I start a PHP variable name with the # symbol?
Should we always declare a variable in PHP specifying its data type?
Is it true that all statements in PHP should end with a comma?
Thursday, September 4, 2008
Variables in PHP
Variables are identifiers to the memory location to store data. A PHP program can contain as many variables as you’d want.
Variable names in PHP begin with a dollar sign "$" and the values are assigned using the “=” operator.
Following the $ sign should be an alphabet or an underscore.
A variable name can contain any number of alphabets, numbers or underscores.
A PHP variable name cannot contain special characters like *, +, @, # etc.
In PHP we need not specify the variable type, as PHP takes the data type of the assigned value.
1. $1name is an invalid variable name as it starts with a number.
2. $_name or $name1 are, however, valid PHP variable names.
3.
$Name = "David";
$Age = 16;
In the above case, we assign values to the variable without mentioning their type. PHP automatically recognizes $Age as a numeric variable and $Name as a string.
Some PHP Exercises
Can I have HTML tags in a PHP file?
Is it true that all PHP statements should end with a comma?
Wednesday, September 3, 2008
A PHP File
A PHP program could be written with a simple text editor such as notepad. In order to develop web pages that look better, web development applications such as Macromedia Dreamweaver could also be used.
A PHP file would contain PHP statements, functions etc. as well as HTML tags and scripts. However, there could be PHP files that contain no HTML.
PHP files are usually saved with the extension, ".php”.
All statements in PHP end with a semicolon.