note 95446 deleted from simplexmlelement.asXML by danbrown

From: Date: Mon, 04 Jan 2010 16:03:41 +0000
Subject: note 95446 deleted from simplexmlelement.asXML by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-164612@lists.php.net to get a copy of this message
Note Submitter: webmaster at netsupportchat dot com ---- 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

« previous php.notes (#164612) next »