Reputation: 67
Ok guys,
Essentially, im loading a simplexml_load_file from a URL like this
$stats = simplexml_load_file("http://example.com/api/api.asmx/Campaign.GetSummary?ApiKey=$apikey&CampaignID=$CID");
Which returns this
SimpleXMLElement Object
(
[Recipients] => 1
[TotalOpened] => 0
[Clicks] => 0
[Unsubscribed] => 0
[Bounced] => 0
[UniqueOpened] => 0
)
After I load that up I want to echo the info, so I try to echo it out like so
echo '<ul id="views">';
echo '<li>';
print $stats['Recipients'];
echo '</li>';
echo '</ul>';
But when it runs, I dont get any of the data, just an empty <li></li>
Upvotes: 0
Views: 174
Reputation: 6087
When working with SimpleXMLElements, you do not use the []
notation - instead you use ->
. So, your code should be:
echo '<ul id="views">';
echo '<li>';
print $stats->Recipients;
echo '</li>';
echo '</ul>';
I believe such notation may (it does in my application, but I am not overly familiar with SimpleXMLElements) return a SimpleXMLElement object, not a string - you can cast it to a string/int/whatever to use it in comparisons etc.
Upvotes: 1
Reputation: 10583
SimpleXMLElement Object
is not an array, it is an Object, the clue is in the name :-)
You need to access it using Object notation
$stats->Recipients
Upvotes: 1