PHP: Easy Dynamic Websites

PHP is the most popular scripting language on the web, and the reason for that is how easy it makes it to create dynamic websites quickly. If you're already a programmer, you'll be able to learn the basics of PHP in about five minutes, and if you're not then it probably won't take much longer. Getting Started in PHP There's a tradition in programming that the first thing you do in any language is say 'Hello World'. Well, here's how you do that in PHP. First of all, create a file in your server's root directory called index.php. Put this text in it: Let's look at this bit by bit. The first line means 'what follows is PHP code'. 'echo' is the PHP command to send text to the web browser, and each line of PHP has to end with a semicolon. Finally, the last line means 'end of the PHP code'. Now, the power of PHP is that those start and end tags can do anywhere in a normal HTML document, as many times as you like. For example: my page - <?php echo date(); ?> This is a complete HTML document with pieces of embedded PHP. The first PHP section inserts the date into the title, and the second writes the answer to 1 + 1 (that's 2, you know) as the content of the document - the word with a dollar before it is a variable, storing the result of the sum. Where this all becomes extremely useful is that your PHP code can open a connection to a database, read data from it, and then the text into a template, along with other things from the database like the headline, the author's name and the date it was written. Useful PHP Functions Here's a quick reference of the most useful PHP functions to help you get started. date. This function returns the date in a format you specify using letters. For example, date("D j M Y") outputs dates in this format: Mon 1 Jan 2010. echo. Writes text to the document. You can use