2

I need to get the value of url2 from the following xml:

<videoplayer>
    <embed_code>aaa</embed_code>
    <volume>bbb</volume>
    <stats_pixel>
        <secret>ccc</secret>
        <url>ddd</url>
        <url2>HOW TO GET THIS???</url2>
        <video_plays>
            <site_url>eee</site_url>
        </video_plays>
    </stats_pixel>
</videoplayer>

This didn't work:

$xml = simplexml_load_file($url);
$xml->videoplayer[0]->stats_pixel->url2;

2 Answers 2

1

videoplayer is root, so you shouldn't specify it, this should work:

echo $xml->stats_pixel->url2;;
Sign up to request clarification or add additional context in comments.

Comments

0

You might need to encode your URL:

$xml = simplexml_load_file(rawurlencode($url));
var_dump($xml);  //make sure you get a SimpleXMLElement here before using it...

2 Comments

I do get an object back. Funny thing is if I var_dump $xml->videoplayer I get SimpleXMLElement Object ( ) anything beyond that I get nothing back but the trying to get property of non object notice.
@JakeRow123 Can you add the output of var_dump($xml->videoplayer); to your question?

Your Answer

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