Advantages of PHP
If you ask a group of PHP programmers why they use PHP, you will hear a range of answers—"it's fast," "it's easy to use," and more. This section briefly summarizes the main reasons for using PHP as opposed to a competing language.
The HTML Relationship
When used to output text, PHP is embedded inside the text in code islands, in contrast to languages like Perl, where text is embedded inside the Perl script. The most common way to open and close PHP code blocks is by <?php and ?>. Here is an example of a simple page, shown in Perl first and then in PHP—don't worry about what the code means for now:
#!/usr/bin/perl
print <<"EOHTML"
<html>
<body>
<p>Welcome, $Name</p>
</body>
</html>
EOHTMLAnd now in PHP:
<html>
<body>
<p>Welcome, <?php print $Name; ?></p>
</body>
</html>The PHP version is only three lines shorter but easier to read, because it doesn't have the extra complexity around it. Some modules for Perl (particularly CGI.pm) help, but PHP continues to have a lead in terms of readability. If you wanted to, you could write your PHP script like the Perl script: switch to PHP mode and print everything out from there.
Apart from legibility, another advantage to having most of the page in HTML is that it makes it possible to use integrated development environments (IDEs), whereas products like Dreamweaver and FrontPage muddle up Perl's print statements.
Interpreting Versus Compiling
Behind the scenes, PHP compiles your script down to a series of instructions (called ...