Jump to content

Get youtube id from url...


ikin

Recommended Posts

Well I'm trying to learn regex so I can use it on my bot but I can't seem to do it right...

I was using http://www.spaweditor.com/scripts/regex/index.php for a while and came up with this:

/watch\?v=(.*)/

To parse: iIp7OnHXBlo out of

 

But it only ended taking the new word to like if I had

Cake is good http://www.youtube.com/watch?v=iIp7OnHXBlo do you like cake?

it would take with the

iIp7OnHXBlo do you like cake?

instead of only the

iIp7OnHXBlo

So yea I need some help...

Code:

            if (preg_match('/watch\?v=(.*)/', $dh->getircTrailing()." ", $trackkeys)) {
                if ($trackkeys != "") {
                    $feedURL = 'http://gdata.youtube.com/feeds/api/videos/' . $trackkey[1];
                    $entry = simplexml_load_file($feedURL);
                    $video = parseVideoEntry($entry);
                    $dh->reply("[Youtube} Title: {$video->title} | By: {$video->author} (uploaded on " . convert_tz($video->published, UTC) . ") | Duration: " . sprintf("%0.2f", $video->length / 60) . " | Views: {$video->viewCount} | Rating: {$video->rating}");
                }
            }

Link to comment
https://forums.phpfreaks.com/topic/219111-get-youtube-id-from-url/
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.