Starting PHP- Part 2Continued from part1 In this section we are going to look at the basic building blocks of PHP. File ExtensionsPHP files are usually given a .php file extension. The file extension tells the web server to pass the file to the php interpreter rather than just displaying it. However it is possible to configure the server to treat any file extension as a php file and pass it to the php interpreter. This is useful when moving from a static site to a dynamic site or/and if you want the visitors to see .htm file extensions as that is what many are used it. This is accomplished on apache servers by editing the .htaccess file. The exact method will vary according to your implementation. Here is the code for you need to add to the .htaccess files for 1and 1. #parsing PHP in html files PHP StatementsPHP Statements end with a semi colon (;) eg
<?php Also just as for html extra white space characters are ignored so you can use newlines, tab and spaces to make your code more readable. PHP VariablesA variable contains data which can be changed.
PHP ConstantsConstants contain data that cannot be changed. They are created using the built-in define function. e.g define("MAXIMUM", 20); sets MAXIMUM equal to 20. By convention constants are in capitals. Putting it togetherThe code <?php Produces variable is =30
as output |
|