Tuesday, April 23, 2013

Filter out iframe using preg match for dailymotion video thumb image.


Get the Iframe src url.
Given  url  replace the term “embed”  to  “ thumbnail”.
Put this url to image src display the thumb image.

 Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Daily Motion Thumb Image</title>
</head>

<body>
<?php 

$str = "<iframe frameborder=\"0\" width=\"480\" height=\"270\" src=\"http://www.dailymotion.com/embed/video/xz7bnq\"></iframe><br /><a href=\"http://www.dailymotion.com/video/xz7bnq_nabilla-discotheque-le-29-ou-pas_news\" target=\"_blank\">NABILLA @ Discoth&egrave;que LE 29... Ou Pas...</a> <i>par <a href=\"http://www.dailymotion.com/discothequele29\" target=\"_blank\">discothequele29</a></i>" ;

$str1 = stripslashes($str);
preg_match('/<iframe.*src=\"(.*)\".*><\/iframe>/isU', $str1, $matches);
echo '1'.($matches[0])."<br/>"; //only the <iframe ...></iframe> part
echo '2'.($matches[1])."<br/>";

$php_mot_url = $matches[1];

$php_mot_url1 = str_replace("embed","thumbnail",$matches[1]);

echo "<br/> <br/>";

?>

<img src="<?php echo $php_mot_url1; ?>">
</body>
</html>

OUTPUT:


No comments:

Post a Comment