Reputation: 4914
I am having problems with simple adding text value to an associative array. Here's part of my code
if($count > 0){
echo $ns_content->encoded;//test works i see the content
$itemnode = array (
'imgurl' => $item->imgurl,
'title' => $item->title,
'desc' => $item->description,
'content' => $ns_content->encoded,
'link' => $item->link,
'date' => $item->pubDate,
);
array_push($feed, $itemnode);
}
print_r($feed);
Just echoing the $ns_content->encoded works,but when i insert the value in the array for later use, it stays empty?? This is also the case for description. The only thing is they are both multiline text with html tags, can this be the problem???
regards
Upvotes: 0
Views: 198
Reputation: 1028
maybe if($count > 0)
not working? did u try putting print_r
inside if
?
Upvotes: 1
Reputation: 175
CDATA? I think sometimes CDATA got in my way when trying to parse feeds. Try SimpleXML with the LIBXML_NOCDATA
flag maybe?
Upvotes: 1
Reputation: 12537
It seems like you are using SimpleXML
to access the XML-document. If you want to store the value of a node as string, then you have to cast it to a string (otherwise you only have a reference to a SimpleXMLElement
instance).
There are three ways of doing that:
// strval and (string)-cast call __toString()
$str = strval($item->description);
$str = (string)$item->description;
// call __toString() directly, might blow up if "$item->description" is no object
$str = $item->description->__toString();
Upvotes: 1
Reputation: 11552
Your HTML is probably being rendered. Try:
echo '<pre>' . print_r($feed, 1) . '</pre>';
Upvotes: 0