Hello,
I am taking the URL’s query string and trying to store the contents into an array for future use.
I thought I cracked it this morning, but my regular expression is wrong.
I would ideally like:
- To store each query string element into a key/value array
- But but my limited skillset has restricted me to storing just the key into an array
My regular expression finds matches but it was not what I expected:
- it prints a series of “=” onto my page.
I find regular expressions a confusing syntax - could anyone let me know what I have done wrong.
What would be nice:
- Tell me what is wrong with my reg ex today why does it not print the contents of the url after the “=” and not just the “=”
I have also failed in an alternative pattern, it prints everything!!! I assumed the following tells the server to… find a word before a “=” give me what “=” is suffixed with
$urlArr2 = preg_match("/[?=\\w=]+/",$urlEl,$match);
- How would I enhance this function to store a key => value pair for future comparison / action
<?php
function splitURL($url)
{
$pageURL = urldecode($url);
$pageURL = parse_url($pageURL,PHP_URL_PATH);
$urlArr = preg_split("/[\\&]+/",$pageURL,null);
foreach($urlArr as $urlEl)
{
$urlArr2 = preg_match("/[?==]+/",$urlEl,$match);
foreach($match as $urlEl1)
{
echo "<h5>$urlEl1</h5>\
\ ";
}
}
return $pageURL;
}
splitURL($_SERVER['QUERY_STRING']);
Many thanks