Search code examples
phpiframepreg-match

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


Solution

  • 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)