Jump to content

Need help parsing out URL from Youtube embed string


eysikal

Recommended Posts

First off, I am new and I apologize if I have not posted this in the correct forum.

 

What I need to do is fairly simple, but I am not familiar enough with the string functions in PHP to do it.

 

I am trying to:

 

Parse out the URL from the embed code string that Youtube generates.

 

Here is an example embed string:

<object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/mzOWr3Fbtk0&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/mzOWr3Fbtk0&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed></object>

 

I am trying to pull out only the "http://www.youtube.com...etc" from the "<param name="movie" tag.

 

Can someone help me with this? I am unsure if this would best be done with regular expressions or with a PHP string function.

 

Thanks.

try this

<?php
$html = '<object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/mzOWr3Fbtk0&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/mzOWr3Fbtk0&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed></object>';
if (preg_match('%<param .*?value="(http://www\.youtube\.com[^"]+)"%s', $html, $regs)) {
$link = $regs[1];
echo $link;
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.