SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
Thread: preg_match - Youtube ID
-
Apr 13, 2008, 17:11 #1
preg_match - Youtube ID
Well I am attempting to grab all the ID's of videos in a search on YouTube.
I absolutely suck at patterns and regex, so I need a bit of help.
PHP Code:<?php
include "config.php";
require_once CLASSES . "core.php";;
require_once CLASSES . "youtube.php";
$core = new core();
$yt = new youtube();
// Time to get the URL's //
$url = "http://www.youtube.com/results?search_query=fall+out+boy";
$page = file_get_contents($url);
preg_match("/watch?v=([^*]+)/i", $page, $matches);
print_r($matches);
?>
Can anyone help?
-
Apr 13, 2008, 19:22 #2
- Join Date
- Nov 2004
- Location
- New Jersey
- Posts
- 317
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You need to use preg_match_all(), escape the question mark, and specify what it ends with. Also better to note that it starts with /.
PHP Code:preg_match_all("/\/watch\?v=(.*?)\"/i", $page, $matches);
$id_array = $matches[1];
print_r($id_array);
-
Apr 13, 2008, 19:37 #3
Thanks
Although I figured it out without using preg.
Thanks =]
-
Apr 13, 2008, 19:38 #4
- Join Date
- Nov 2004
- Location
- New Jersey
- Posts
- 317
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Actually this is better, because there might be additional parameters in the URL.
PHP Code:preg_match_all("/\/watch\?v=(.*?)[&\"]/i", $page, $matches);
-
Apr 14, 2008, 10:59 #5
Might wanna use their API and parse the feed with simplexml: http://code.google.com/apis/youtube/...ing_for_Videos
Saul
Bookmarks