HOW TO WRITE (Web site design) PHP SCRIPTS solution saves you

HOW TO WRITE PHP SCRIPTS solution saves you time in the long run. Instead of you needing to update the copyright statement every year, the PHP code does it automatically. You write the code once and forget it. What s more, as you ll see in the next chapter, if you need to amend the code, it s possible to do so by updating only one page, and the changes are reflected on every page of your site. This ability to display the correct year automatically relies on two key aspects of PHP: variables and functions. As the name suggests, functions do things; they perform preset tasks, such as getting the current date and converting it into human-readable form. I ll cover functions a little later, so let s take variables first. The script in Figure 3-1 contains two variables: $startYear and $thisYear. A variable is simply a name that you give to something that may change or that you don t know in advance. Variables in PHP always begin with $ (a dollar sign). Although the concept of variables sounds abstract, we use variables all the time in everyday life. When you meet somebody for the first time, one of the first things you ask is What s your name? It doesn t matter whether the person you ve just met is Tom, Dick, or Harry, we use the word name in the same way as PHP uses variables. The word name remains constant, but the value we store in it varies for different people. Similarly, with your bank account, money goes in and out all of the time (mostly out, it seems), but as Figure 3-2 shows, it doesn t matter whether you re scraping the bottom of the barrel or as rich as Croesus, the amount available at any particular time is always referred to as the balance. Figure 3-2. The balance on your bank statement is an everyday example of a variable the name stays the same, even though the value may change from day to day. So, name and balance are everyday variables. Just put a dollar sign in front of them, and you have two ready-made PHP variables, like this: $name $balance Simple.
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

Leave a Reply