How do i select certain part of url.

Discussion in 'PHP' started by dawilster, Jun 13, 2009.

  1. #1
    Hi guys,

    Lets say I wanted to select a certain part of a link such as http://megavideo.com/?v=SQPDLVO0

    But what if i just wanted the SQPDLVO0 part what should i do.

    Thanks a lot
     
    dawilster, Jun 13, 2009 IP
  2. dfreeman

    dfreeman Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If the format of the link is always like that str_replace will do:

    $link="http://megavideo.com/?v=SQPDLVO0";

    $linkCode=str_replace("http://megavideo.com/?v=","",$link);

    echo $linkCode;
     
    dfreeman, Jun 13, 2009 IP
  3. matthewrobertbell

    matthewrobertbell Peon

    Messages:
    781
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #3
    $code = preg_match('v=(.+?)$',$url);
     
    matthewrobertbell, Jun 13, 2009 IP
  4. dawilster

    dawilster Active Member

    Messages:
    844
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #4
    thanks guys works perfectly.
     
    dawilster, Jun 13, 2009 IP