2

I'm using PHP Simple HTML DOM Parser to parse an HTML file, but I'm unable to parse the "data-extension" attribute of an "a" tag. The HTML looks like this:

<a href="/websitenews.html" class="video" data-extension='{"mediaObj":{"url":"http://a-website.com/ondemand/226/217.js","offset":"0.0"}}' title="Video start">

My PHP code looks like this:

foreach($html->find('a[class=video]') as $e) {
  echo $e->data-extension;
}

But all it is echoing is a series of zeros. How can I echo the url within the data-extension, i.e., "http://a-website.com/ondemand/226/217.js" ? Thanks.

1 Answer 1

1

My solution:

foreach($html->find('a[class=video]') as $e)
{
  $json = json_decode($e->{'data-extension'});
  foreach($json as $key=>$data)
  {
    echo $data->url;
  } 
}
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah what he said

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.