Sometimes, we want to get URL query string parameters with PHP.
In this article, we’ll look at how to get URL query string parameters with PHP.
How to get URL query string parameters with PHP?
To get URL query string parameters with PHP, we use the parse_url
function.
For instance, we write
$url = "www.mysite.com/category/subcategory?myqueryhash";
echo parse_url($url, PHP_URL_QUERY);
to call parse_url
with $url
and PHP_URL_QUERY
to return the query string part odf the $url
as an associative array with the keys and values.
Conclusion
To get URL query string parameters with PHP, we use the parse_url
function.