Thursday, February 2, 2012

extract ifrmae source url using php

extract ifrmae source url using php


<?php

$str='<iframe width="560" height="315" src="http://www.youtube.com/embed/7VopPJIWIDc" frameborder="0" allowfullscreen></iframe>';

$DOM = new DOMDocument;

$DOM->loadHTML($str); // Your string


//get all anchors

$anchors = $DOM->getElementsByTagName('iframe');


//display all hrefs

for ($i = 0; $i < $anchors->length; $i++){

echo $anchors->item($i)->getAttribute('src');

}


?>



You can check if the node has a srcusing hasAttribute() first if necessary.