views:

24

answers:

2

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>

Any help would be greatly appreciated guys, Thanks in advance.

+1  A: 

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.

Stephen
Thanks, cant believe that slipped my mind. Really appreciate it sir.
Warren Haskins
+1  A: 

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
jakenoble
Thanks sir, apprecaite it.
Warren Haskins