note 81256 added to function.dom-domdocument-savehtml
| From: | mjaque at ilkebenson dot com | Date: | Wed, 20 Feb 2008 09:48:51 +0000 |
| Subject: | note 81256 added to function.dom-domdocument-savehtml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136303@lists.php.net to get a copy of this message | ||
Regarding last note, you can post-process saveXML string in order to close empty tags with the
following function:
<?php
function cerrarTag($tag, $xml){
$indice = 0;
while ($indice< strlen($xml)){
$pos = strpos($xml, "<$tag ", $indice);
if ($pos){
$posCierre = strpos($xml, ">", $pos);
if ($xml[$posCierre-1] == "/"){
$xml = substr_replace($xml, "></$tag>", $posCierre-1, 2);
}
$indice = $posCierre;
}
else break;
}
return $xml;
}
?>
At least script and select empty elements should be closed. This example shows how it can be used:
<?php
define("CABECERA_XHTML", '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">');
$xhtml = $docXML->saveXML($docXML->documentElement);
$xhtml = cerrarTag("script", $xhtml);
$xhtml = cerrarTag("select", $xhtml);
$xhtml = CABECERA_XHTML."\n".$xhtml;
echo $xhtml;
?>
----
Server IP: 69.147.83.197
Probable Submitter: 87.217.61.105
----
Manual Page -- http://www.php.net/manual/en/function.dom-domdocument-savehtml.php
Edit -- https://master.php.net/note/edit/81256
Del: integrated -- https://master.php.net/note/delete/81256/integrated
Del: useless -- https://master.php.net/note/delete/81256/useless
Del: bad code -- https://master.php.net/note/delete/81256/bad+code
Del: spam -- https://master.php.net/note/delete/81256/spam
Del: non-english -- https://master.php.net/note/delete/81256/non-english
Del: in docs -- https://master.php.net/note/delete/81256/in+docs
Del: other reasons-- https://master.php.net/note/delete/81256
Reject -- https://master.php.net/note/reject/81256
Search -- https://master.php.net/manage/user-notes.php