Writing PHP - 2

PHP output

With or without database access and graphics capability, PHP is still a useful language for modern web sites. The spread of XML and WML is a nightmare for designers of conventional sites. After so much time dealing with multiple browsers using the idea of cross-brower pages, there are suddenly two new formats that cannot be combined with HTML. The thought of writing two or even three identical sites is enough of a problem, without considering learning XML and WML. XSLT can be used to export xHTML - reducing duplication, but WML is not so easy. PHP solves these problems by allowing the designer to create one set of PHP files that can output WML, XML, XHTML, DHTML, HTML and any future flavours of the base language, SGML. If it's a text based markup language then PHP can output it. With additional libraries, it can even handle non-text output like PNG and JPEG graphics.

This set of PHP files demonstrate this capability. The PHP code creates variables for the links and the page content, including titles and headings, then PHP code (identical in each page) formats the bare content in a manner suitable for WML, XML and HTML. In the case of the CodeHelp site, the HTML is v4 - DHTML using CSS. In fact it uses the same CSS stylesheets as the rest of the CodeHelp site. It could just as easily output HTML3 or a frame based site suitable for older browsers not capable of using CSS.

The PHP code looks for a WAP device using the HTTP headers, looks for XSLT by looking for Microsoft Internet Explorer 5 or later and uses HTML for every other case. Preset blocks of code are then set only if the browser matches and the content of the variables are inserted into the output. The actual code downloaded to the browser shows no sign of the PHP behind it. (The use of these pages to demonstrate WML output is the reason why these pages are shorter than others on this site. WML has a strict limit on the total file size of the downloaded WML code.)



This is part of www.codehelp.co.uk Copyright © 1998-2004 Neil Williams
See the file about.html for copying conditions.