Hi,
Ok. To begin with this thread, I am using the codes found on:
But this is a different topic altogether and so don’t get confused with the other thread.
Look at these 2 codes. They do the same thing in 2 different ways. They extract the values from the query part of the string and print on your screen.
1.
[code]
$url = ‘https://www.username:[email protected]:8080/dir/subdir/file.php?arg=value1&key=value2#fragment’;
echo $all_queries_and_values = parse_url($url,PHP_URL_QUERY); echo ‘<br>’;
parse_str($all_queries_and_values,$arr1);
print_r($arr1); echo ‘<br>’; //DEVMODE.
echo $arr1[‘arg’]; echo ‘<br>’; //Echoes the Value. Not the Key.
echo $arr1[‘key’]; echo ‘<br>’; //Echoes the Value. Not the Key.
2.
[code]
$url = ‘https://www.username:[email protected]:8080/dir/subdir/file.php?arg=value1&key=value2#fragment’;
echo $all_queries_and_values = parse_url($url,PHP_URL_QUERY); echo ‘<br>’;
parse_str($all_queries_and_values,$arr2);
print_r($arr2); echo ‘<br>’; //DEVMODE.
var_dump($arr2); echo ‘<br>’; //DEVMODE.
foreach($arr2 AS $single_query_value)
{
echo $single_query_value; echo ‘<br>’; //Echoes the Value. Not the Key.
}
I now want to print on your screen not only the values (like shown on the above 2 codes) but the keys alongside the values like so:
[code]
key=>value
How to do this ?
These ain’t working …
**The difference between the below 3 codes are these ….
key=>value
“key”=>”value”
key->value
[code]
$url = ‘https://www.username:[email protected]:8080/dir/subdir/file.php?arg=value1&key=value2#fragment’;
echo $all_queries_and_values = parse_url($url,PHP_URL_QUERY); echo ‘<br>’;
parse_str($all_queries_and_values,$arr2);
print_r($arr2); echo ‘<br>’; //DEVMODE.
var_dump($arr2); echo ‘<br>’; //DEVMODE.
foreach($arr2 AS $single_query_key=>$single_query_value)
{
echo $single_query_key=>$single_query_value; echo ‘<br>’; //I want it to echo both the Keys and the Values. Not the Key.
}
**Parse error: syntax error, unexpected token “=>”, expecting “,” or “;” in C:xampphtdocsWorkgulfTemplatesparse_string_TEMPLATE.php on line 70
Neither this working …
**_(Note the comment at the bottom) …
[code]
$url = ‘https://www.username:[email protected]:8080/dir/subdir/file.php?arg=value1&key=value2#fragment’;
echo $all_queries_and_values = parse_url($url,PHP_URL_QUERY); echo ‘<br>’;
parse_str($all_queries_and_values,$arr2);
print_r($arr2); echo ‘<br>’; //DEVMODE.
var_dump($arr2); echo ‘<br>’; //DEVMODE.
foreach($arr2 AS “”$single_query_key””=>””$single_query_value””)
{
echo “$single_query_key”=>”$single_query_value”; echo ‘<br>’; //I want it to echo both the Keys and the Values. Not the Key.
}
**Parse error: syntax error, unexpected token “=>”, expecting “->” or “?->” or “{” or “[” in C:xampphtdocsWorkgulfTemplatesparse_string_TEMPLATE.php on line 90
Nope! Fail too ….
[code]
echo $all_queries_and_values = parse_url($url,PHP_URL_QUERY); echo ‘<br>’;
parse_str($all_queries_and_values,$arr2);
print_r($arr2); echo ‘<br>’; //DEVMODE.
var_dump($arr2); echo ‘<br>’; //DEVMODE.
foreach($arr2 AS “$single_query_key”->”$single_query_value”)
{
echo “$single_query_key”->”$single_query_value”; echo ‘<br>’; //Echoes the Value. Not the Key.
}
**Parse error: syntax error, unexpected double-quote mark, expecting identifier or variable or “{” or “$” in C:xampphtdocsWorkgulfTemplatesparse_string_TEMPLATE.php on line 110