note 91842 added to function.simplexml-element-asXML
| From: | Anonymous at osu1 dot php dot net | Date: | Sun, 28 Jun 2009 11:23:14 +0000 |
| Subject: | note 91842 added to function.simplexml-element-asXML | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-157642@lists.php.net to get a copy of this message | ||
Getting the subtree without the start and end tags:
$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 />' ;
----
Server IP: 195.221.21.36
Probable Submitter: 84.103.5.213
----
Manual Page -- http://www.php.net/manual/en/function.simplexml-element-asXML.php
Edit -- https://master.php.net/note/edit/91842
Del: integrated -- https://master.php.net/note/delete/91842/integrated
Del: useless -- https://master.php.net/note/delete/91842/useless
Del: bad code -- https://master.php.net/note/delete/91842/bad+code
Del: spam -- https://master.php.net/note/delete/91842/spam
Del: non-english -- https://master.php.net/note/delete/91842/non-english
Del: in docs -- https://master.php.net/note/delete/91842/in+docs
Del: other reasons-- https://master.php.net/note/delete/91842
Reject -- https://master.php.net/note/reject/91842
Search -- https://master.php.net/manage/user-notes.php