tags:

views:

40

answers:

1

This is what I've got so far:

<?php

 $content = "word1 http://www.youtube.com/watch?v=yqfKe-67foQ&amp;feature=related word2 http://www.youtube.com/watch?v=2vq7gDEn99Y&amp;feature=related word3 http://www.youtube.com/watch?v=nW5HxgMYRto\nhttp://www.youtube.com/watch?v=8Uc2lpH0iZ0&amp;feature=fvhl";
 $pattern = '/http:\/\/www\.youtube\.com\/watch\?(.*)v=([a-zA-Z0-9_\-]+)(\S*)/i';
 $replace = '<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/$2&amp;amp;hl=en_US&amp;amp;fs=1"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/$2&amp;amp;hl=en_US&amp;amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>';

 $content = preg_replace($pattern, $replace, $content);
 echo $content;

?>

I honestly have no idea why it doesn't work. Some help would be appreciated. Thanks.

+1  A: 

You just have to make * non-greedy:

http:\/\/www\.youtube\.com\/watch\?(.*?)v=([a-zA-Z0-9_\-]+)(\S*)

See "Watch out for greediness".

Artefacto
A thousand thanks kind sir :). Works like a charm.
pandronic