parse_url questioin

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • deko

    parse_url questioin

    Why does this code fail?

    $ref = http://example.com/?p=32
    $ref_a = parse_url($ref) ;
    echo ref_a['path']; //returns nothing

    Does the '?' cause parse_url to fail?

    I'm trying to capture a referrer in an user agent that contains a query string.

    As a work-around, I'm using this:

    $urlPath = stristr(substr( $urlString, 9), '/');

    Other alternatives?

    Thanks in advance.


  • Curtis

    #2
    Re: parse_url questioin

    deko wrote:
    Why does this code fail?
    >
    $ref = http://example.com/?p=32
    $ref_a = parse_url($ref) ;
    echo ref_a['path']; //returns nothing
    >
    Does the '?' cause parse_url to fail?
    >
    I'm trying to capture a referrer in an user agent that contains a query
    string.
    >
    As a work-around, I'm using this:
    >
    $urlPath = stristr(substr( $urlString, 9), '/');
    >
    Other alternatives?
    >
    Thanks in advance.
    >
    >
    There are two syntax errors in your code:

    1. $ref = http://example.com/?p=32 - you need quotes around this.
    2. echo ref_a['path'] - you did not precede the variable name with $

    Once you fix those, the path element has a value of "/".

    Comment

    • deko

      #3
      Re: parse_url question

      >$ref = http://example.com/?p=32
      >$ref_a = parse_url($ref) ;
      >echo ref_a['path']; //returns nothing
      There are two syntax errors in your code:
      >
      1. $ref = http://example.com/?p=32 - you need quotes around this.
      2. echo ref_a['path'] - you did not precede the variable name with $
      >
      Once you fix those, the path element has a value of "/".
      Yeah, that was a sloppy post.

      But even after making your suggested corrections, the code is not returning
      '/?p=32', but rather '/', as you pointed out. So I guess parse_url() does not
      work when the url path contains a query string.

      Comment

      • Rik

        #4
        Re: parse_url question

        On Mon, 12 Feb 2007 09:42:50 +0100, deko <deko@nospam.co mwrote:
        >>$ref = http://example.com/?p=32
        >>$ref_a = parse_url($ref) ;
        >>echo ref_a['path']; //returns nothing
        >
        >There are two syntax errors in your code:
        >>
        >1. $ref = http://example.com/?p=32 - you need quotes around this.
        >2. echo ref_a['path'] - you did not precede the variable name with $
        >>
        >Once you fix those, the path element has a value of "/".
        >
        Yeah, that was a sloppy post.
        >
        But even after making your suggested corrections, the code is not
        returning '/?p=32', but rather '/', as you pointed out. So I guess
        parse_url() does not work when the url path contains a query string.
        Please read the manual when having questions about a specific function.
        The query string is a separate part of the url...



        --
        Rik Wasmus

        Comment

        • deko

          #5
          Re: parse_url question

          The query string is a separate part of the url...
          sweet!

          Comment

          Working...