HTML and CSS Reference
In-Depth Information
If you're a Mac user, you also have the option of using MAMP, another free package that
combines Apache, PHP, and MySQL. It can be downloaded from
Mac users also have the option of using the version of Apache and PHP that are included
with OS X.
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 the lesson on JavaScript 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
statements look similar from one to the other, it's because they are.
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, 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 some exam-
// My function starts here.
$color = 'red'; // Set the color for text on the page
# $color = 'blue';
$color = $old_color; # Sets the color to the old color.
// $color = 'red';
Search WWH ::

Custom Search