I have these urls from a web log:
http://www.domain.com/page?s=194&client=151678&m=a4a&v=1&g=54 http://www.domain.com/page?s=51&client=617171&m=b4z&v=8&g=97
How can I convert this URL in an array in PHPso i will have an array like this
array( 'page' => array( 's' => 194, 'client' => 151678 'm' => 'a4a', 'v' => 1, 'g' => 54 ) etc.. )
then later I can loop to that array to find duplicates or validate the information correctly.
You can make use of serialize() and urlencode PHP built-in function to pass an array as URL param. The serialize() function will return a sequence of bits for the input given and the urlencode will again encode the values as well the special characters available in it.
PHP | parse_url() Function The parse_url() function is an inbuilt function in PHP which is used to return the components of a URL by parsing it. It parses an URL and return an associative array which contains its various components.
PHP $_GET is a PHP super global variable which is used to collect form data after submitting an HTML form with method="get". $_GET can also collect data sent in the URL. Assume we have an HTML page that contains a hyperlink with parameters: <html> <body>
The http_build_query() function is an inbuilt function in PHP which is used to generate URL-encoded query string from the associative (or indexed) array.
PHP has a native function for that, the parse_str function. You can use it like:
parse_str($_SERVER['QUERY_STRING'], $outputArray);
This will do just what you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With