HTML and CSS Reference
In-Depth Information
Statements in PHP, as in JavaScript, are terminated with a semicolon. (You can see the
semicolon at the end of the statement in the example.) There's no reason why you can't
include multiple statements within one PHP tag, like this:
<?php
echo “Hello “;
echo “world!”;
?>
PHP also provides a shortcut if all you want to do is print the value of something to a
page. Instead of using the full PHP tag, you can use the expression tag, which just
echoes a value to the page. Instead of using
<?php echo “Hello world!”; ?>
You can use this:
<?= “Hello world!” ?>
Replacing php with = enables you to leave out the call to the echo function and the semi-
colon. This style of tag is referred to as a short tag . Not all PHP installations have short
tags enabled.
Getting PHP to Run on Your Computer
Before you can start writing your own PHP scripts, you need to set up a PHP environ-
ment. The easiest approach is probably to sign up for a web hosting account that pro-
vides PHP support. Even if you do so, though, there are some advantages to getting PHP
to work on your own computer. You can edit files with your favorite editor and then test
them right on your own computer rather than uploading them to see how they work.
You'll also be able to work on them even if you're not online. Finally, you can keep from
putting files on a server that your users see without your having tested them first.
To process PHP pages, you need the PHP interpreter and a web server that works with
the PHP interpreter. The good news is that PHP and the most popular web server,
Apache, are both free, open source software. The bad news is that getting PHP up and
running can be a bit of a technical challenge.
Fortunately, if you're a Windows or Mac user, someone else has done this hard work for
you. A tool called XAMPP, available for both Windows and OS X, bundles up versions
of Apache, PHP, and MySQL (a database useful for storing data associated with web
applications) that are already set up to work together. (The last P is for Perl, another script-
ing language.) You can download it from http://www.apachefriends.org/en/xampp.html.
21
 
 
 
Search WWH ::




Custom Search