i am working with an xml, using simplexml and xpath now when i echo a result of xpth query it echoing string but i need to get that string in a array, but when trying to copy in a array it is coming as and simplexml object, like
object(SimpleXMLElement)#237 (1) {
[0]=>
string(69) "Hallituksen esitykset uusiksi Yle-laeiksi eduskunnan käsiteltäviksi"
}
is just want "Hallituksen esitykset uusiksi Yle-laeiksi eduskunnan käsiteltäviksi" here is the code,
$xml = "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" . $pageBlocks['news'];
$xmldata = simplexml_load_string($xml);
$result = $xmldata->xpath('/blocks/block/items/item/strong');
$feeddata = array();
while (list(, $node) = each($result)) {
$feeddata [] = $node[0];
}
foreach ($feeddata as $data){
var_dump($data);
}
how to solve that
To get it as a string, simply cast it via (string)
, which will internally call SimpleXMLElement's __toString()
to return a string representation. That's what's also happening implicitly when you echo
it, incidentally.
while (list(, $node) = each($result)) {
$feeddata [] = (string)$node[0];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.