Source for file HTMLtoXHTML.php
Documentation is available at HTMLtoXHTML.php
* $Id: HTMLtoXHTML.php,v 1.4 2007/12/01 22:00:19 dufuz Exp $
* Demonstrates conversion of HTML to XHTML
require_once 'XML/HTMLSax3.php';
function HTMLtoXHTMLHandler ()
// Handles the writing of attributes - called from $this->openHandler()
function writeAttrs ($attrs)
foreach ($attrs as $name => $value) {
if ($name == 'checked') {
$this->xhtml.= ' checked="checked"';
} else if ($name == 'selected') {
$this->xhtml.= ' selected="selected"';
$this->xhtml.= ' '. $name. '="'. $value. '"';
function openHandler (&$parser, $name, $attrs)
if ((isset ($attrs['id']) && $attrs['id'] == 'title') || $name == 'title') {
$this->xhtml .= '<input';
$this->writeAttrs ($attrs);
$this->writeAttrs ($attrs);
$this->xhtml .= "<br />\n";
$this->xhtml .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"eng\">\n";
if ($this->pCounter != 0 ) {
$this->xhtml .= '<'. $name;
$this->writeAttrs ($attrs);
function closeHandler (&$parser, $name)
if ($name == 'body' && $this->pCounter != 0 ) {
$this->xhtml .= "</p>\n";
$this->xhtml .= "</". $name. ">\n";
// Character data handler
function dataHandler (&$parser, $data)
$this->xhtml .= $this->inTitle ? 'This is XHTML 1.0' : $data;
function escapeHandler (&$parser, $data)
if ($data == 'doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"') {
$this->xhtml.= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
// Return the XHTML document
// Instantiate the handler
$handler = & new HTMLtoXHTMLHandler ();
// Instantiate the parser
// Register the handler with the parser
$parser->set_object ($handler);
$parser->set_element_handler ('openHandler','closeHandler');
$parser->set_data_handler ('dataHandler');
$parser->set_escape_handler ('escapeHandler');
echo $handler->getXHTML ();
Documentation generated on Mon, 11 Mar 2019 15:11:50 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|