Raymond Irving wrote:
Hello,
After talking with Michael about how to generate XHTML code using the DOM I came up with this little function that I'm thinking of using to generate XHTML code that's HTML compatible:
function saveXHTML($dom) {
$html = $dom->saveXML(null,LIBXML_NOEMPTYTAG);
$html = str_replace(' ','',$html);
$html = preg_replace('/<\?xml[^>]*>\n/','',$html,1);
$html = preg_replace('/<\!\[CDATA\[(.*)\]\]><\/script>/s','//<![CDATA[\1//]]></script>',$html);
$html = preg_replace('/><\/(meta|link|base|basefont|param|img|br|hr|area|input)>/',' />',$html);
return $html;
}
What do you think?
__
Raymond Irving
I found this in my old files - don't know if any of it is useful to you -
function HTMLify($buffer) {
$xhtml[] = '/<script([^<]*)\/>/';
$html[] = '<script\\1></script>';
$xhtml[] = '/<div([^<]*)\/>/';
$html[] = '<div\\1></div>';
$xhtml[] = '/<a([^<]*)\/>/';
$html[] = '<a\\1></a>';
$xhtml[] = '/\/>/';
$html[] = '>';
// DOMDocument never produces white space between / and > on self
closing tags
// $xhtml[] = '/\/\s+>/';
// $html[] = '>';
return preg_replace($xhtml, $html, $buffer);
}
I think I actually had extended the function beyond the replacements
there, but I don't seem to have them anymore.
What really would be nice is to patch the libxml2 library to add an
option to change it's default behaviour of screwing up utf8 on html
export and then be able to pass that option to saveHTML() so the utf8
issue would go away.
That's way beyond my skill though. Has anyone brought up the issue with
the libxml developers?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php