note 95446 added to simplexmlelement.asXML
| From: | webmaster at netsupportchat dot com | Date: | Mon, 04 Jan 2010 07:37:39 +0000 |
| Subject: | note 95446 added to simplexmlelement.asXML | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-164580@lists.php.net to get a copy of this message | ||
Adaptation of "Anonymous" June 2009 post without start/end tags, instead as a
SimpleXMLElement Class Extension (cleaner in my eyes):
<?php
class acclXMLElement extends SimpleXMLElement {
function innerXML($filename = false) {
$tag = $this->getName();
$s = $this->asXML();
if(substr($s,0,1+strlen($tag))!='<'.$tag) return false;
$news='';
for($i=1+strlen($tag);$i<strlen($s);$i++){
if(substr($s,$i,1) == '>') break;
}
$news=substr($s,$i+1);
if( substr($news,strlen($news)-strlen($tag)-3) !='</'.$tag.'>') return
false;
else $news = (substr($news,0,strlen($news)-strlen($tag)-3));
if($filename) {
return file_put_contents($filename, $news);
} else {
return $news;
}
}
}
?>
then use;
<?php
$xml = simplexml_load_string($xml, 'acclXMLElement');
?>
Thanks,
Ben Carroll @ http://www.netsupportchat.com
----
Server IP: 208.69.120.55
Probable Submitter: 67.236.74.94
----
Manual Page -- http://www.php.net/manual/en/simplexmlelement.asXML.php
Edit -- https://master.php.net/note/edit/95446
Del: integrated -- https://master.php.net/note/delete/95446/integrated
Del: useless -- https://master.php.net/note/delete/95446/useless
Del: bad code -- https://master.php.net/note/delete/95446/bad+code
Del: spam -- https://master.php.net/note/delete/95446/spam
Del: non-english -- https://master.php.net/note/delete/95446/non-english
Del: in docs -- https://master.php.net/note/delete/95446/in+docs
Del: other reasons-- https://master.php.net/note/delete/95446
Reject -- https://master.php.net/note/reject/95446
Search -- https://master.php.net/manage/user-notes.php