Welcome to PHP
Posted: Wed Jan 05, 2005 2:06 pm
PHP has quickly become one of the most popular web-development languages in the world ([url="http://www.php.net/usage.php"]usage statistics[/url]), so why wouldn't you want to learn it? Easier said than done, but if you do want to learn at least a little bit of PHP then listen up. This how-to will run you through the fundamentals of PHP. However, before then lets take a look at the facts:
In order for the PHP interpreter to start parsing PHP script, you must first define a start and stop point for PHP instructions. A number of tags can be used, depending on their avaliability. The tags supported by PHP are:
echo and print
PHP has two constructs which output expressions to a browser. Neither of these are functions and therefore parenthesis isn't required:
There is a subtle difference between the two constructs - print will act as a function and will always return a Boolean value. Since it is not required to return any value, echo is usually faster, although only marginally so.
Satements
A statement is a command which the interpreter must execute. This could be an expression, call to an object or function or numerous other constructs built into PHP. A simple example statement is: A statement must end in a semicolon to avoid a parse error from the interpreter.
Variables
To make PHP similar to almost every other language PHP facilitates the use of variables. Variables can store one value at a time (including an array) and can be changed numerous times in the execution of a script (they can be varied...hence the name). In PHP variables are prefixed with the dollar sign ($) and are case sensitive, so $variable is different from $Variable. Also, unlike certain languages (eg VB) PHP doesn't require the variable to be declared prior to use.
Constants
The opposite of a variable is a constant. Once defined it cannot be changed during the execution of a script. A constant must be created using the define() function, here is an example:The define() function takes 2 arguments (and 1 optional). The first is a string of the name of our constant, in this instance "CONSTANT". The second is the value of our constant, here we set it to the integer 17. The third optional arugment specifies whether the constant is case insesitive. By default a constant is case sensitive (uppercase by convention - variables lowercase) but passing true as the last argument will cause (for example) CONSTANT to be the same as CONstanT.
Hopefully that shows you the basics of the PHP language. I've tried to make this as clear as possible, but if something is unclear - just ask /good.gif' class='bbc_emoticon' alt='(Y)' />
- PHP stands for PHP: Hypertext Preprocessor (its a recursive acronym)
- PHP is a scripting language which is interpreted instead of compiled
- PHP is developed using syntax from C, Perl and Java including some new creations aswell.
- PHP is currently on its 5th major release, however PHP 4 is still the most used version.
- More information or installation help can be found at [url="http://www.php.net"]PHP.net[/url]
In order for the PHP interpreter to start parsing PHP script, you must first define a start and stop point for PHP instructions. A number of tags can be used, depending on their avaliability. The tags supported by PHP are:
- The normal php tags to close
- Short PHP tags
- HTML type script tags <script language="php"> and (seldom used)
- ASP type tags
echo and print
PHP has two constructs which output expressions to a browser. Neither of these are functions and therefore parenthesis isn't required:
Code: Select all
<?php
print("Hello");
//works the same as
print "Hello";
?>Satements
A statement is a command which the interpreter must execute. This could be an expression, call to an object or function or numerous other constructs built into PHP. A simple example statement is:
Code: Select all
echo "This is a statement";Variables
To make PHP similar to almost every other language PHP facilitates the use of variables. Variables can store one value at a time (including an array) and can be changed numerous times in the execution of a script (they can be varied...hence the name). In PHP variables are prefixed with the dollar sign ($) and are case sensitive, so $variable is different from $Variable. Also, unlike certain languages (eg VB) PHP doesn't require the variable to be declared prior to use.
Constants
The opposite of a variable is a constant. Once defined it cannot be changed during the execution of a script. A constant must be created using the define() function, here is an example:
Code: Select all
<?php
define("CONSTANT", 17);
echo CONSTANT;
?>Hopefully that shows you the basics of the PHP language. I've tried to make this as clear as possible, but if something is unclear - just ask /good.gif' class='bbc_emoticon' alt='(Y)' />