Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Jun 2013
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need some help with preg_match

    Hello Anders Falk here! I'm not so good with preg_match so this is why I have choose to create a thread here... Anyway I wonder how to just take out the video id from a youtube link? Only the video id.

    I got the site filmbladet.se and I really need help with this. So what can it be?... Some links looks like this and it's very annoying!

    http://www.youtube.com/watch?v=mgNmB...tra_param=true

    Other links have some sort of gdata_youtube behind.

  • #2
    wlf
    wlf is offline
    New Coder
    Join Date
    Aug 2012
    Posts
    61
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Hi angry,

    With id you mean the mgNmBePiBaM bit?
    A good programmer is someone who looks both ways before crossing a one-way street. Free hosting

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    For that one you can do something like this:
    PHP Code:
    if( preg_match'%youtube\.com/watch\?v=(\w+)%'$subject$match ) )
    {
        
    $result $match[0];

    I'm not sure if YouTube video IDs may contain any other characters, though.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You can also parse the querystring out of a full url provided:
    PHP Code:
    $qs parse_url('http://utub.com/?v=stuff&otherstuff=something'PHP_URL_QUERY);
    parse_str($qs$aQS);
    printf("id under the 'v': %s"$aQS['v']); 
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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