I have this regex patter to grab YouTube video ID's
preg_match_all( '/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/ ]{11})/i', $string, $res );
However it doesn't seem to work properly with the string in the example bellow:
<?php
$string = "yet, another youtube video.
[url=http://www.youtube.com/watch?feature=player_embedded&v=6kVpM5WK5JI#]http://www.youtube.com/watch?feature=player_embedded&v=6kVpM5WK5JI#[/url]
Fonte:onothersite";
preg_match_all( '/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/ ]{11})/i', $string, $res );
print_r($res);
?>
The code above outputs this:
Array (
[0] =>
Array (
[0] => youtube.com/watch?feature=player_embedded&v=6kVpM5WK5JI#]http://www.youtube.com/watch?feature=player_embedded&v=6kVpM5WK5JI#[/url] Font
)
[1] =>
Array (
[0] => url] Font
)
)
And should output this:
Array (
[0] =>
Array (
[0] => youtube.com/watch?v=6kVpM5WK5JI
)
[1] =>
Array (
[0] => 6kVpM5WK5JI
)
)
Any idea how to solve this?
Thanks.