Extracting Part of an URL

Discussion in 'PHP' started by Icheb, Feb 11, 2007.

  1. #1
    Say I have this URL

    http://www.google.com/search?hl=en&q=digitalpoint&btnG=Google+Search

    Now I want to extract what the user has searched for. I think I remember there being a function that takes the URL apart and stores this data in an array, but for the life of me I can't remember what that function was.

    I'm not asking for a regular expression, I could do that myself.
     
    Icheb, Feb 11, 2007 IP
  2. phper

    phper Active Member

    Messages:
    247
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    parse_url() is what you're after
     
    phper, Feb 11, 2007 IP
    Icheb likes this.
  3. Icheb

    Icheb Peon

    Messages:
    1,092
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Come to think of it, with that function I'd still have to use a regular expression to get the q part. :/
    I thought there was a function that also takes the query string apart.
     
    Icheb, Feb 11, 2007 IP
  4. phper

    phper Active Member

    Messages:
    247
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #4
    You don't have to use regex if you don't want to.
    explode() et al can give you what you want as well, although with regex it would just be a quick one liner.
     
    phper, Feb 11, 2007 IP
  5. Icheb

    Icheb Peon

    Messages:
    1,092
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Duh, of course! :)
     
    Icheb, Feb 11, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    parse_str() might be useful as well.
     
    nico_swd, Feb 12, 2007 IP
    Icheb likes this.
  7. Icheb

    Icheb Peon

    Messages:
    1,092
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Holy crap you people are awesome. :)
     
    Icheb, Feb 12, 2007 IP