Forum Moderators: DixonJones
<?php
$string = "search.php?go=search&Suchbegriff=&PLZ=&Stadt=&BundeslandDeutschland=Baden&BundeslandOesterreich=&KantonSchweiz=&Land=&Submit=Suchen";
?>
I only want the Strings(Substrings) between the '&'-chars each. Secondly i want to display them in some kind of order:
Suchbegriff=
PLZ=
Stadt=
BundeslandDeutschland=Baden
BundeslandOesterreich=
KantonSchweiz=
Land=
Submit=Suchen
Could somebody help me with the corresponding RegEx?
Thanks
Code:
<?php
$string =
"/de/partner/search.php?go=search&Suchbegriff=&PLZ=&Stadt=&BundeslandDeutschland=Baden-Wuerttemberg&BundeslandOesterreich=&KantonSchweiz=&Land=&Submit=Suchen";
$muster = "/&+([^&])*/";
$res = array();
preg_match_all($muster,$string,$res);
print_r($res);
foreach($res[0] as $output){
echo $output."<br/>\n";
}
?>
Output:
&Suchbegriff=
&PLZ=
&Stadt=
&BundeslandDeutschland=Baden-Wuerttemberg
&BundeslandOesterreich=
&KantonSchweiz=
&Land=
&Submit=Suchen
You may also want to check into the PHP functions, parse_url() [php.net] and parse_str [php.net].
[regex.osherove.com...]