note 91842 deleted from simplexmlelement.asXML by danbrown

From: Date: Fri, 28 Jan 2011 14:32:45 +0000
Subject: note 91842 deleted from simplexmlelement.asXML by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-176439@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- Getting the subtree without the start and end tags: <?php $string = <<<XML <a> <b> <c>text <b>hello</b><i>hello</i></c> <c>stuff</c> </b> <d> <c>hella</c> </d> </a> XML; //================================= function subTree( $s , $tag ){ 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; return(substr($news,0,strlen($news)-strlen($tag)-3)); } //================================= $xml = new SimpleXMLElement($string); echo '<textarea rows="10" cols="40">' . $xml->asXML() . '</textarea><br />'; echo '<textarea rows="6" cols="40">' . $xml->b->asXML() . '</textarea><br />' ; echo '<textarea rows="6" cols="40">' . subTree( $xml->b->asXML() , 'b' ) . '</textarea><br />' ; ?>

« previous php.notes (#176439) next »