note 85674 added to book.simplexml
| From: | gwhitescarver at yahoo dot com | Date: | Thu, 11 Sep 2008 20:02:32 +0000 |
| Subject: | note 85674 added to book.simplexml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-144343@lists.php.net to get a copy of this message | ||
Moving some code from a PHP 5.2.6 / Windows environment to a 5.2.0 / Linux environment, I somehow
lost access to a plain text node within a SimpleXML Object. On a var_dump of $xml_node, a [0]
element was shown as the string '12'. However, $xml_node[0] was evaluating NULL in 5.2.0.
You can see below the code change I made, pulling my data out of the raw XML with a regular
expression. Hope this is useful to someone.
//In some versions of PHP it seems we cannot access the [0] element of a SimpleXML Object.
Doesn't work in 5.2.0:
//$count = $xml_node[0];
//grab the raw XML:
$count = ($xml_node->asXML());
//pull out the number between the closing and opening brace of the xml:
$count = preg_replace('/.*>(\d*)<.*/', '$1', $count);
----
Server IP: 209.41.74.194
Probable Submitter: 12.198.162.130
----
Manual Page -- http://www.php.net/manual/en/book.simplexml.php
Edit -- https://master.php.net/note/edit/85674
Del: integrated -- https://master.php.net/note/delete/85674/integrated
Del: useless -- https://master.php.net/note/delete/85674/useless
Del: bad code -- https://master.php.net/note/delete/85674/bad+code
Del: spam -- https://master.php.net/note/delete/85674/spam
Del: non-english -- https://master.php.net/note/delete/85674/non-english
Del: in docs -- https://master.php.net/note/delete/85674/in+docs
Del: other reasons-- https://master.php.net/note/delete/85674
Reject -- https://master.php.net/note/reject/85674
Search -- https://master.php.net/manage/user-notes.php