ptg16476052
654 LESSON 24: Taking Advantage of the Server
If you’re a Mac user, you also have the option of using MAMP, another free package
that combines Apache, PHP, and MySQL. You can download it from https://
http://www.mamp.info/en/.
If you like to tinker with your Mac, you have the option of using
the version of Apache and PHP that are included with OS X. But
this can be challenging. Using a prebuilt system is quicker.
TIP
After you’ve installed XAMPP (or MAMP), you just have to start the application to get
a web server up and running that you can use to develop your pages. To test your PHP
pages, you can put them in the htdocs directory inside the XAMPP install directory. For
example, if you want to test the hello.php page I talked about earlier, you could put it in
the htdocs directory. To view it, just go to http://localhost/hello.php.
If that doesn’t work, make sure that XAMPP has started the Apache server. If you’re
using MAMP, the steps are basically the same. Just put your pages in the htdocs folder,
as with XAMPP.
The PHP Language
When you think about the English language, you think about it in terms of parts of
speech. Nouns name things, verbs explain what things do, adjectives describe things, and
so on. Programming languages are similar. A programming language is made up of vari-
ous “parts of speech,” too. In this section, I explain the parts of speech that make up the
PHP language—comments, variables, conditional statements, and functions.
It might be helpful to think back to Lesson 19 as you read this lesson. PHP and
JavaScript share a common ancestry, and many of the basic language features are similar
between the two. If things such as the comment format, curly braces, and control state-
ments look similar from one to the other, it’s because they are.
Comments
Like HTML and JavaScript, PHP supports comments. PHP provides two comment styles:
one for single-line comments, and another for multiple comments. (If you’re familiar
with comments in the C or Java programming language, you’ll notice that PHP’s are the
same.) First, I'll cover single-line comments. To start a single-line comment, use // or #.
Everything that follows either on a line is treated as a comment. Here are som e examples:
// My function starts here.
$old_color = 'purple';