note 101967 modified in book.simplexml by danbrown
| From: | danbrown@php.net | Date: | Thu, 20 Jan 2011 17:08:22 +0000 |
| Subject: | note 101967 modified in book.simplexml by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-175942@lists.php.net to get a copy of this message | ||
An easer way to get the text node if you can't access to [0] property of the simpleXMLElement
is to use the sprintf function.
As gwhitescarver at yahoo dot com said, in some version of php 5 it is hard to access to text node
of an element, but when you print the element, the [0] property is automaticaly returned.
Like if you echo() the element, the text node is return.
The sprintf function do the same:
<?php
$a = array();
foreach ($xml->children() as $child) {
$a[$child->getName()] = sprintf("%s", $child);
}
?>
--was--
An easer way to get the text node if you can't access to [0] property of the simpleXMLElement
is to use the sprintf function.
As gwhitescarver at yahoo dot com said, in some version of php 5 it is hard to access to text node
of an element, but when you print the element, the [0] property is automaticaly returned.
Like if you echo() the element, the text node is return.
The sprintf function do the same:
$a = array();
foreach ($xml->children() as $child) {
$a[$child->getName()] = sprintf("%s", $child);
}
http://php.net/manual/en/book.simplexml.php