Results 1 to 3 of 3
Jul 12, 2010, 15:40 #1
- Join Date
- Mar 2004
- U.K (Wales)
- 0 Post(s)
- 0 Thread(s)
Using regular Expressions to strip Youtube URL from Movie ID
Hi I have a site which allows users to enter their details along with a youtube video link. This then gets added to a database. I want a page which displays all the submitted videos, using the Youtube API..
I've worked out how to pull the Videoentry meta data to create thumbnails for a video.. but I want to grab the full url which the user entered from my database.. run it through some regular expressions to get rid of the http://www.youtube.com/watch?v=TF3fCM0c7xE(red part) and store the id in a variable. I want to then call the meta data based on the video id using the:
$videoEntry = $yt->getVideoEntry('TF3fCM0c7xE');
Can anyone help me with this?
Jul 12, 2010, 17:16 #2
- Join Date
- Jul 2003
- Northeastern USA
- 56 Post(s)
- 1 Thread(s)
You can use this:
And use explode() with the & symbol on the query section of the URL.
Then, search exploded array for 'v=' and retrieve the value following 'v=' using substr().
Jul 13, 2010, 00:58 #3
Force Flow, good suggestion with parse_url() to get the query string. However, why explode/substr when you could make good use of parse_str()?
$url = 'http://www.youtube.com/watch?v=TF3fCM0c7xE';
parse_str(parse_url($url, PHP_URL_QUERY), $query);
$video_id = isset($query['v']) ? $query['v'] : NULL;
Software Developer and PHP Manual Author.