note 81256 deleted from domdocument.savehtml by danbrown

From: Date: Wed, 13 May 2009 13:40:31 +0000
Subject: note 81256 deleted from domdocument.savehtml by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154556@lists.php.net to get a copy of this message
Note Submitter: mjaque at ilkebenson dot com ---- 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; ?>

« previous php.notes (#154556) next »