Is there a PHP equivalent of Perl's URI::ParseSearchString?
I'm doing some work for a client that involves parsing the referrer information from Google et al to target various parts of a page to the user's search keywords.
I noticed that Perl's CPAN has a module called URI开发者_JAVA技巧::ParseSearchString which seems to do exactly what I need. The problem is, I need to do it in PHP.
So, to avoid reinventing the wheel, does anyone know if there is a library out there for PHP that does the same / similar thing?
parse_str()
is what you are looking for.
You may additionally want to use parse_url()
to get the search string.
I'm the author of the module. As far as I know, I've never seen something similar for PHP. If you do come across anything, please do let me know.
That being said, I cannot image this being very hard to port to PHP and I can have an attempt at it if you dont find anything similar out there.
Spiros
Maybe this is too inefficient or the http_referer isn't showing the full uri ...
function parse_uri($uri) {
if (substr_count('?', $uri) > 0) {
$queryString = explode('?', $uri);
return parse_str($queryString[1]);
} else {
return parse_str($uri);
}
}
if (isset($_SERVER['HTTP_REFERER'])) {
print_r(parse_uri($_SERVER['HTTP_REFERER']));
}
精彩评论