WEB Whats the best way to strip the imdb id from a url in php?

Discussion in 'OT Technology' started by o2, Sep 21, 2009.

  1. o2

    o2 Witty Title Here OT Supporter

    Joined:
    Oct 4, 2005
    Messages:
    16,099
    Likes Received:
    11
    Location:
    Toronto
  2. dazmanultra

    dazmanultra New Member

    Joined:
    Jun 17, 2002
    Messages:
    34,795
    Likes Received:
    0
    Location:
    English Countryside
    Explode around /title/

    is the ID always going to have a fixed length or can it change?
     
  3. fishbulb

    fishbulb Active Member

    Joined:
    Oct 29, 2001
    Messages:
    6,848
    Likes Received:
    4
    Location:
    md
    Code:
    $url =  'http://www.imdb.com/title/tt0274518/';
    
    $url_array = explode("/",$url);
    
    $id_index = array_search("title",$url_array) + 1;
    
    $movie_id = $url_array[$id_index];
    
    
     
  4. o2

    o2 Witty Title Here OT Supporter

    Joined:
    Oct 4, 2005
    Messages:
    16,099
    Likes Received:
    11
    Location:
    Toronto
    why didnt I think of that? lol

    works great, thanks
     
  5. illectronic

    illectronic I'm Coming Home OT Supporter

    Joined:
    Jan 19, 2005
    Messages:
    16,950
    Likes Received:
    0
    Location:
    Brooklyn
    i hate php/perl character match
     
  6. hank85

    hank85 sudo shred /dev/sda -f -v -z --iterations=6

    Joined:
    Jul 23, 2008
    Messages:
    4,360
    Likes Received:
    0
  7. illectronic

    illectronic I'm Coming Home OT Supporter

    Joined:
    Jan 19, 2005
    Messages:
    16,950
    Likes Received:
    0
    Location:
    Brooklyn
  8. drpepper

    drpepper Active Member

    Joined:
    Nov 13, 2006
    Messages:
    38,076
    Likes Received:
    2
    Location:
    San Antonio
  9. noon

    noon get high and teach me how to listen

    Joined:
    May 4, 2002
    Messages:
    3,384
    Likes Received:
    0
    Location:
    Lawrence, KS

    don't forget to account for the /title/tt0274518 type urls...

    Code:
    $pattern = '/title\/([^\/]+)/i';
    
     
  10. Fase

    Fase Your Face, In A Pickle Jar.

    Joined:
    Apr 6, 2004
    Messages:
    29,540
    Likes Received:
    0
    Location:
    Windsor, Ont, Canada.
  11. fishbulb

    fishbulb Active Member

    Joined:
    Oct 29, 2001
    Messages:
    6,848
    Likes Received:
    4
    Location:
    md

Share This Page