PHP - Page 18
November 11, 2002
PHP: Hypertext Preprocessor (PHP) is a
server-side scripting language that can be embedded in HTML pages. It has
been around for a few years now, but has undergone significant changes over
that time. PHP borrows much of its syntax from Perl. When it was first created,
it was intended to provide a more trimmed-down, easier-to-write, HTML-embeddable
alternative to Perl, a task at which it seems to have succeeded. PHP is free,
cross-platform, open source software; it integrates with all major web servers
on all major operating systems.
Advantages
-
It's open source and freely available
from http://www.php.net/.
-
It's cross-platform.
-
It has a very active user community.
-
It's seen as having a light footprint and not being processor-intensive.
Drawbacks
-
It's relatively difficult to expand the language to add non-standard
functionality that not handled by its built-in functions.
-
PHP's extensibility is limited compared to say, Java, ASP,
and COM (although new libraries pop up with every release)
-
The function syntax to connect to each different brand of database
is slightly different. Compare this to Java, which has a generic JDBC interface
to connect to databases or ASP, which has its ADO abstraction layer.
XML Support
PHP has 4 extensions for performing XML tasks. Perhaps the most widely used
of these are the XML parser functions – these use the Expat
library, a SAX-based parser. Although it can parse XML, it does not perform
any validation of the document. It supports 3 character encodings, namely
US-ASCII, ISO-8859-1 and UTF-8, but does not support UTF-16. As you already
know, with a SAX parser you define event handlers for XML events: as the parser
works through the XML document it will call these handlers as and when events
occur. The Expat library can be found at http://www.jclark.com/xml/.
PHP can also do DOM parsing of the XML document, but at the moment this extension
is considered experimental. The extension is being overhauled for PHP 4.3.0
and the behaviour of many of the functions may change, so when using this
extension it is best to avoid any non-object-oriented function (a full list
of deprecated functions is available with the documentation). The extension
uses the Gnome XML library, which you can find at http://www.xmlsoft.org/.
The PHP extension that provides XSLT support currently supports the Sablotron
library. This extension has recently been rewritten in order to provide support
for other libraries like Xalan and libxslt. Sablotron can be found at http://www.gingerall.com/.
For our PHP examples here to work properly, you need to make
sure you have the XSLT and XML DOM extensions installed. Don't worry, as
they are included in the PHP package downloadable from http://www.php.net/do_download.php?download_
file=php-4.2.2-Win32.zip (see the InstallPHP.txt file in the code download for
more instructions on installing this properly).
Finally, PHP also contains RPC support through the XMLRPC extension, although
this is also considered experimental.
Server Used for Examples
For the examples in this chapter, we used Apache 1.3.26 and PHP 4.2.2 on
Windows 2000 Professional.
Server-Side Languages - Page 17
Practical XML for the Web
JSP - Page 19
|