467,871 Members | 1,707 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,871 developers. It's quick & easy.

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.
Feb 12 '07 #1
  • viewed: 1699
Share:
4 Replies
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 "/".
Feb 12 '07 #2
>$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.

Feb 12 '07 #3
Rik
On Mon, 12 Feb 2007 09:42:50 +0100, deko <de**@nospam.comwrote:
>>$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...

http://www.php.net/parse_url

--
Rik Wasmus
Feb 12 '07 #4
The query string is a separate part of the url...
http://www.php.net/parse_url
sweet!
Feb 12 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Ted G | last post: by
4 posts views Thread by futureofphp | last post: by
2 posts views Thread by Nothing | last post: by
13 posts views Thread by Roman Mashak | last post: by
3 posts views Thread by deko | last post: by
reply views Thread by jack112 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.