Contents / Previous / Next


PHP Basics

Executing PHP:
You can open a PHP file in a browser or use the command-line tool "php": $> php hello_world.php

File Extensions:
Files including PHP code must end with extensions .php or .phtml to be recognized form the web server.

Tags:
PHP script tags are "<?php" to open a PHP region and "?>" to close it (or "<?" and "?>", if short_open_tag is set in the PHP configuration file or <% and %> for Active Server Pages, ASP). Anything in between these tags is considered to be PHP code.

Expressions:
Expressions end with a semicolon ; . They may contain line breaks.

Comments:
PHP supports 'C', 'C++' and Unix shell-style comments: // and # comments the rest of a line and /* and */ comment the inclosed region.

Variables:
Variables start with a dollar sign $. The variable name is case-sensitive, they must start with a letter or underscore.

Strings:
Strings are inclosed in quotation marks: "string". The backslash \ keeps the next character from being interpreted.

PHP info:
You can use the phpinfo() function to get information about the PHP installation and state, etc:

<?php phpinfo(); ?>