0

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>

1
  • 2
    Have you tried $stats->Recipients? Commented Sep 2, 2010 at 10:57

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, cant believe that slipped my mind. Really appreciate it sir.
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.