Filter out iframe using preg match
I'm trying to filter out the iframe in my post, my post looks like this
<!--videoplayer--><iframe title="YouTube video player" class="youtube-player" type="text/html" width="200" height="200" src="http://www.youtube.com/embed/IIYeKGNNNf4?rel=0" frameborder="0" allowFullScreen></iframe><!--endvideoplayer-->Blitz performs at Desifest 2010 in Toronto Canada, & Films music video with Navin Kundra for the song "Love You The Same" feat Kat Eyez & produced by Roach Killa from Blitz's new album "Get Blitz". Join my fanpage for more: WWW.FACEBOOK.COM/BLITZMUSIC *Special thanks to: Deesha, Dj 开发者_开发问答Jump Off, Paul The Drummer, Surgeon, Umar, Navin Kundra, Nyrone, Sats B, Kat Eyez, B Don. (New Album Coming Soon!)
I would just like to return the iframe not the post description, so from is what I want.
Thank you
preg_match('/<iframe.*src=\"(.*)\".*><\/iframe>/isU', $string, $matches);
echo ($matches[0]); //only the <iframe ...></iframe> part
echo ($matches[1]); //the src part. (http://www.youtube.com/embed/IIYeKGNNNf4?rel=0)
I see the same error over and over again, using regex to parse html, USE A HTML DOM PARSER.
include("simple_html_dom.php") ;
$string = <<< EOF
"<!--videoplayer--><iframe title="YouTube video player" class="youtube-player" type="text/html" width="200" height="200" src="http://www.youtube.com/embed/IIYeKGNNNf4?rel=0" frameborder="0" allowFullScreen></iframe>
<!--endvideoplayer-->Blitz performs at Desifest 2010 in Toronto Canada, & Films music video with Navin Kundra for the song "Love You The Same" feat Kat Eyez & produced by Roach Killa from Blitz's new album "Get Blitz". Join my fanpage for more: WWW.FACEBOOK.COM/BLITZMUSIC *Special thanks to: Deesha, Dj Jump Off, Paul The Drummer, Surgeon, Umar, Navin Kundra, Nyrone, Sats B, Kat Eyez, B Don. (New Album Coming Soon!)"
EOF;
$html = str_get_html($string);
foreach($html->find('iframe') as $element)
{
echo $element->src . '<br>';
}
outputs :
http://www.youtube.com/embed/IIYeKGNNNf4?rel=0
preg_match('#<iframe(.*?)></iframe>#is', $string, $matches);
echo $matches[1]; // 0 for <iframe></iframe> part.
精彩评论