note 96619 added to simplexmlelement.asXML

From: Date: Mon, 08 Mar 2010 18:54:00 +0000
Subject: note 96619 added to simplexmlelement.asXML
Groups: php.notes 
Request: Send a blank email to php-notes+get-166794@lists.php.net to get a copy of this message
When you are using asXML() method it also outputs start and end tag of root element. For example : <?php $xml = "<text> Something <b>new</b> </text>" $obj = simplexml_load_string($xml); $obj->asXML(); //returns xml text with "text" tag ?> To remove start and end tag of asXML() result I wrote simple function that uses regular expressions. <?php /** * Getting $content of formatted expression * "<tag attributes>$content</tag>". Tag will * automatically determined. * * @author QoSyS * @return content of the tag */ function subXML($s){ $s = preg_replace('#[\n\r]+#', "\\n", $s); $pattern = '#<([A-Za-z][A-Za-z0-9]*)\b[^>]*>(.*?)</\1>#i'; preg_match($pattern, $s, $matches); //print_r($matches); return $matches[2]; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 91.78.81.169 ---- Manual Page -- http://www.php.net/manual/en/simplexmlelement.asXML.php Edit -- https://master.php.net/note/edit/96619 Del: integrated -- https://master.php.net/note/delete/96619/integrated Del: useless -- https://master.php.net/note/delete/96619/useless Del: bad code -- https://master.php.net/note/delete/96619/bad+code Del: spam -- https://master.php.net/note/delete/96619/spam Del: non-english -- https://master.php.net/note/delete/96619/non-english Del: in docs -- https://master.php.net/note/delete/96619/in+docs Del: other reasons-- https://master.php.net/note/delete/96619 Reject -- https://master.php.net/note/reject/96619 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#166794) next »