HOW TO WRITE PHP SCRIPTS and much, much (Web hosting reviews)
HOW TO WRITE PHP SCRIPTS and much, much more. You can identify functions in PHP code because they re always followed by a pair of parentheses. Sometimes the parentheses are empty, as in the case of phpversion(), which you used in phptest.php in the previous chapter. Often, though, the parentheses contain variables, numbers, or strings, like this line of code from the script in Figure 3-1: $thisYear = date(’Y'); This calculates the current year and stores it in the variable $thisYear. It works by feeding the string ‘Y’ to the built-in PHP function date(). Placing a value between the parentheses like this is known as passing an argument to a function. The function takes the value in the argument and processes it to produce (or return) the result. For instance, if you pass the string ‘M’ as an argument to date() instead of ‘Y’, it will return the current month as a three-letter abbreviation (e.g., Mar, Apr, May). As the following example shows, you capture the result of a function by assigning it to a suitably named variable: $thisMonth = date(’M'); The date() function is covered in depth in Chapter 14. Some functions take more than one argument. When this happens, separate the arguments with commas inside the parentheses, like this: $mailSent = mail($to, $subject, $message); It doesn t take a genius to work out that this sends an email to the address stored in the first argument, with the subject line stored in the second argument, and the message stored in the third one. You ll see how this function works in Chapter 5. You ll often come across the term parameter in place of argument. There is a tech- nical difference between the two words, but for all practical purposes, they are inter- changeable. As if the 3,000-odd built-in functions weren t enough, PHP lets you build your own custom functions. Even if you don t relish the idea of creating your own, throughout this book you ll use some that I have made. You use them in exactly the same way. Displaying PHP output There s not much point in all this wizardry going on behind the scenes unless you can display the results in your web page. There are two ways of doing this in PHP: using echo or print. There are some subtle differences between the two, but they are so subtle, you can regard them as identical. I prefer echo for the simple reason that it s one fewer letter to type.
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.