Once you've configured your Web server to parse PHP pages, it's time to test it and see if everything's working as advertised. The simplest way to do this is to pop open your favourite text editor and create a file containing these lines of code: Save the file with the extension .php - for example, "test.php" Now, start up your Web browser and point it to the file you just saved - for example, http://localhost/test.php - and you'll see a page filled with what at first glance appears to be gibberish, but on closer inspection will reveal itself to be a list of internal PHP variables. The values of most of these variables can be modified by altering the "php.ini" file that ships with every distribution of PHP. For beginners, the default values are more than sufficient to work with. There's one essential concept that you need to get your mind around before we proceed further. Unlike CGI scripts, which require you to write code to output HTML, PHP lets you create embed PHP code in regular HTML pages, and execute the embedded PHP code when the page is requested. These embedded PHP commands are enclosed within special start and end tags - here's what they look like: Here's a simple example which demonstrates how PHP and HTML can be combined: And if you browse to this page through your browser and take a look at the HTML source, this is what you'll see: Every PHP statement ends in a semi-colon - this convention is identical to that used in Perl, and omitting the semi-colon is one of the most common mistakes newbies make. It's also possible to add comments to your PHP code, as we've done in the example above. PHP supports both single-line and multi-line comment blocks - take a look:
blog comments powered by Disqus |