+ Reply to Thread
Results 1 to 6 of 6

Thread: Parsing youtube video id

  1. #1
    johned is offline Coder johned will become famous soon enough
    Join Date
    Nov 2007
    Posts
    75

    Default Parsing youtube video id

    Has anyone got any experience parsing the video id from youtube urls in php.

    ie.
    youtube.com/watch?v=R0BA-KviNO4&feature=related

    Where the red is the part I want.

  2. #2
    Forbairt's Avatar
    Forbairt is offline respect my AW-THOR-IT-AYY Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough
    Join Date
    Jun 2007
    Location
    My Office, Dublin
    Posts
    2,285

  3. #3
    Forbairt's Avatar
    Forbairt is offline respect my AW-THOR-IT-AYY Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough
    Join Date
    Jun 2007
    Location
    My Office, Dublin
    Posts
    2,285

    Default

    actually judging on your selfmade cms ...

    I'll assume php ?

    Code:
    $string = "youtube.com/watch?v=R0BA-KviNO4&feature=related";
    
    preg_match('/v\=(.+)&/',$string,$matches);
    
    echo $matches[1];
    
    do a semi ok job for you ?

  4. #4
    johned is offline Coder johned will become famous soon enough
    Join Date
    Nov 2007
    Posts
    75

    Default

    I just cracked it without regular expressions from a little googling.

    Here is the code it allows you to enter the url of a youtube vid in to a form and the code processes the form to parse the video id and insert it in to an embed code with preset values.

    PHP Code:
    //parse the id from the url
    $url $_POST['id'];
    $vidparser parse_url($url);
    parse_str($vidparser[query], $query);
    $vidid = ($query['v']);
     
     
    //get the video id in to the embed code
    $content "<object width=\"290\" height=\"235\"><param name=\"movie\" value=\"http://www.youtube.com/v/".$vidid."&hl=en&fs=1&rel=0\"></param><param name=\"allowFullScreen\" value=\"true\"></param><embed src=\"http://www.youtube.com/v/".$vidid."&hl=en&fs=1&rel=0\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" width=\"290\" height=\"235\"></embed></object>"
    seems to work well! I wrote it to a text file for include..

    cheers for your help..
    Last edited by johned; 09-07-2008 at 04:13 PM.

  5. #5
    Forbairt's Avatar
    Forbairt is offline respect my AW-THOR-IT-AYY Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough Forbairt will become famous soon enough
    Join Date
    Jun 2007
    Location
    My Office, Dublin
    Posts
    2,285

    Default

    ah fair enough I'd assumed it'd be part of a multiline post or something similar not just a URL you had

  6. #6
    johned is offline Coder johned will become famous soon enough
    Join Date
    Nov 2007
    Posts
    75

    Default

    No probs just finished it now and i can use the form to send sizes etc to the embed code.. Just hope they dont change anything on there side now lol .

+ Reply to Thread

Similar Threads

  1. IrishVids.com - New YouTube?
    By decbohan22 in forum General Chat
    Replies: 6
    Last Post: 16-07-2008, 04:46 PM
  2. Replies: 2
    Last Post: 29-04-2008, 10:18 AM
  3. suggestions: youtube plugin for wordpress
    By davidbehan in forum Webmaster Discussion
    Replies: 1
    Last Post: 17-10-2007, 05:10 PM
  4. Replies: 0
    Last Post: 21-12-2006, 08:38 PM
  5. Google buy Youtube
    By Cormac in forum General Chat
    Replies: 4
    Last Post: 13-10-2006, 09:25 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Optimization by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64