By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,723 Members | 1,891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,723 IT Pros & Developers. It's quick & easy.

parse_url questioin

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
>$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

P: n/a
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

P: n/a
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.