PHP Basics
A tutorial on the syntax of PHP.
PHP Syntax
PHP is an embedded scripting language which means you can insert PHP inside HTML code - although the file type has to be a PHP file in order for the PHP to work. Also, all PHP statements must end in a semicolon and PHP is not case sensitive. The opening bracket for PHP (to tell the server the code is switching to PHP) is "<?php" and the closing bracket is "?>"PHP Page
|
<?php You write your PHP code here - in between the opening and closing PHP tag. ?> | ||
PHP Check
You can run the following script to see what version of PHP you have as well as information about your PHP configuration. Just place this code inside a PHP file. Then name the file and upload it to your server. Then go to the address and view the output. Also, delete the file after you check it because you don't want people to be able to see this information.PHP Page
|
<?php phpinfo(); ?> | ||
This is how it looks
|
|||||||||||||||||||||||||||||
Comments
Many coders like to document their code by putting in notes telling them what the code means. The comments are not sent to the web browser and therefore are not viewable by the users of your site. There are three different ways to write comments. The first way uses the pound sign to precede the comment and the second kind uses two slashes to precede the comment. Both of these are in-line comments, which means that it will "comment out" anything until you hit the enter key. Many people will still use these for multiple lines of comments like the example below. The third kind of commenting uses "/*" and "*/" for multi-line comments like the last example below. There is also the way to comment out HTML.PHP Page
|
<? The first kind of comments use a pound sign.<br><br> # Comment goes here. The second uses two slashes.<br><br> // Comment goes here. Here the coder is using comments over multiple lines.<br><br> # Comments # More comments # More comments You can put comments on the same line as code if it is after the code, like the following:<br><br> <?php echo php_version; // checks PHP version ?> The third type allows comments over multiple lines.<br><br> /* Using this comment type you can have comments run over multiple lines */ ?> | ||
This is how it looks
|
The first kind of comments use a pound sign. The second uses two slashes. Here the coder is using comments over multiple lines. You can put comments on the same line as code if it is after the code, like the following: The third type allows comments over multiple lines. |
||
Bookmark this page: |









