Re: Generate XHTML (HTML compatible) Code using DOMDocument
| From: | Michael Shadle | Date: | Sun, 12 Apr 2009 16:42:00 +0000 |
| Subject: | Re: Generate XHTML (HTML compatible) Code using DOMDocument | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-291389@lists.php.net to get a copy of this message | ||
On Sun, Apr 12, 2009 at 8:07 AM, Raymond Irving <xwisdom@yahoo.com> 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?
If this will maintain utf-8 I might be able to use it :) which
according to the last thread, saveHTML munges utf-8 stuff due to
libxml...
Hopefully this week I can give it a go.