PHP Syntax
Published on March 4, 2010 @ 7:01 pm
The very first thing to know about PHP is that the code is written within a .php file, not a .html. PHP is executed on the web server and the results are then sent to the browser in the traditional plain HTML format.
Scripting Block
PHP scripting block always begins with <?php and ends with ?>. This way is the recommended way of PHP scripting but there is also another format. On the hosting website server, the shorthand code support must be enabled. This additonal but non recommended way begins its scripting block with <? and ends with ?>. Unlike many scripting languages, PHP is flexible in where you want to put it. The PHP scripting block can be placed anywhere you like in the document, thats anywhere!
Example:
<?php
?>
Commenting in PHP
To comment within PHP the // is used to make a single-line comment or /* and */ is used to make a large comment block that uses more than one line.
Example:
<html>
<body>
<?php
//This is a PHP comment
/*
This is
a PHP comment
block that is over more than one line
*/
?>
</body>
</html>
Simple Script
Now that you have learnt the very basics of PHP you can now create your very first PHP script!
To begin with, this script will consist of the above PHP syntax and also the echo statement. This statement outputs some text to the browser, in this case it would be Hello everyone!
Example:
<html>
<body>
<?php
//The below script outputs the text “Hello everyone!” to the browser
echo “Hello everyone!”;
?>
</body>
</html>
Notice that in this script above, the PHP instruction ends with a semicolon. This semicolon is used as a separator and must be used at the end of every PHP instruction to distinguish where one instruction begins and another ends.
Filed under PHP, Tutorials Permalink


