2

This how my HTML looks like :

<div class="academy_page">
    <span class="academy_page_header">Academy:</span>
    <div>
        <div class="videopage_block" align="center">
            <iframe class="videopage_video" src="//player.vimeo.com/video/67353453644?title=0&amp;byline=0&amp;portrait=0" width="300" height="150" frameborder="0" allowfullscreen="allowfullscreen"></iframe>
            <div class="academy_text">How to Ride a Skateboard</div>
        </div>
        <div class="videopage_block" align="center">
            <iframe class="videopage_video" src="//player.vimeo.com/video/9435345343?title=0&amp;byline=0&amp;portrait=0" width="300" height="150" frameborder="0" allowfullscreen="allowfullscreen"></iframe>
            <div class="academy_text">How to Build a Skateboard</div>
        </div>
</div>

This is how I'm parsing it:

foreach($html->find('div.academy_page') as $element){

        foreach($element->find('div.videopage_block') as $dulce) {

            $item['title'] = $dulce->find('div.academy_text', 0)->plaintext;
            $item['vimeo_url'] = $dulce->find('iframe')->src;

            $returnArray[] = $item;
        }
     }

This is my result in json:

[
  {
    "title": "How to Ride a Skateboard",
    "vimeo_url": null
  },
  {
    "title": "How to Build a Skateboard",
    "vimeo_url": null
  }
]

How do I get my iFrame SRC?

I've also tried $item['vimeo_url'] = $dulce->find('.videopage_video')->plaintext; and nothing

2 Answers 2

1

I guess you can use:

$dom = new DOMDocument();
$dom->loadHTML($html);
$xpath = new DOMXpath($dom);
foreach ($xpath->query("//div[@class='videopage_block']") as $node){

    echo $node->getElementsByTagName('iframe')[0]->getAttribute("src");
    echo $node->getElementsByTagName('div')[0]->nodeValue;
}

Update:

To get the video id:

$iframe_src = $node->getElementsByTagName('iframe')[0]->getAttribute("src")
$video_id = preg_replace('%.*?video/(\d+)\?.*%i', '$1', $iframe_src);
Sign up to request clarification or add additional context in comments.

5 Comments

How do I incorporate this into what I already have? Seems like an easy way to get the src if that's the only thing I needed
Ok, I'll make some adjustments to my answer, 1''
Appreciate it Pedro
Pedro! You're a life saver. This 100% gives me what I needed. One more question, do you know how I can just return the number part of the src? I only need 67353453644 part of //player.vimeo.com/video/67353453644?title=0&amp;byline=0&amp;portrait=0. If you could point me in the right direction I would really appreciate it! Marked as answer
@Walker Please have a look to the updated answer. GL
0

you can point to the src Attribute directly in SimpleHTMLDOM

  $iframe = $html->find( 'iframe' , 1 )->src ;

Reference official manual

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.