Jump to content

recognize a youtube link in a string


AviNahum

Recommended Posts

hey...

i found this code:

   $youtube_customize = "&hl=en&fs=1&color1=0x2b445c&color2=0x4c7499";

   

   // youtube replacement:

   $text = preg_replace('#([\s\(\)])http://([a-z]+\.)?youtube\.com/watch\?v=([0-9a-zA-Z_\-]+)(&[^"\s\(\)<\[\.]*)?#',

      '$1<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/$3' . $youtube_customize . '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param>' .

      '<embed src="http://www.youtube.com/v/$3' . $youtube_customize . '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>', $text);

 

this code recognize a youtube link in a string and convert it to embed code to watch it directly in my website...

for example:

text text text

text text text

 

in this string, the link will be converted to embed code...

this code works fine...

but in my website, im using an editor, and is some cases this editor put links into <A> tags, for example, this link:

 

will be converted to this:

<a href="http://www.youtube.com/watch?v=4WRVwZTS4qU&feature=channel">http://www.youtube.com/watch?v=4WRVwZTS4qU&feature=channel</a>

 

but now, this link cant be converted to a youtube embed video...

anyone knows how i can check if the link located between <A> tags?

 

Thanks!

 

***sorry for my english***

Link to comment
https://forums.phpfreaks.com/topic/215129-recognize-a-youtube-link-in-a-string/
Share on other sites

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.