Jump to content

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;
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.