The problem is this, some case to give: Http://jb51.net?a=1
This type of URL address append parameter changes to: http://jb51.net?a=1&b=2
But how do you know that you already have the same parameter name, for example: http://jb51.net?a=1&a=2
This is not a big mistake, but the address bar looks bad. What about it? With the regular solution bar (originally I want to use PHP string processing solution, but later felt to learn the regular and then use the right to do it)
The following is the background processing method I used to return to the previous page
Copy Code code as follows:
function _goback ($msg =null, $get =array ()) {
$url = $_session[' Backurl '];
if ($get!=array ())
foreach ($get as $k => $g) {
$url. = ' & '. $k. ' = ' $g;//Append all parameters to append, whether or not repeated
if (Explode ("&{$k}=", $url)) (>2) {//If the current URL string is split in the format "&a=" There are more than two split arrays, indicating that the string has duplicate parameters
$url =preg_replace ("/{$k}=[a-za-z0-9]*&/", ", $url);//Replace All" &a=x "as Empty
}
}
unset ($_session[' Backurl '));
$this->alert ($msg, $url);
}
A simple explanation:
"/{$k}=[a-za-z0-9]*&/" If we assume $k= "a", that is "/a=[a-za-z0-9]*&/"
I don't know if I've got it wrong, the meaning is actually a match to "a=", followed by any number of alphanumeric combinations ([a-za-z0-9]*: meaning any single digit or alphabetic character, can be interpreted as a repetition of the preceding arbitrary character, such as u* can be understood as: uuuu ... An unlimited number of u permutations, where the * can be replaced with {0,}, followed by "&."
This is a very simple example, but look at the online description of the regular grammar, the total feeling does not understand, do not know whether I understand the ability of the problem or write people speak too abstruse.
In addition, explain why this can eliminate duplication, the principle is very simple, http://jb51.net?a=1&a=2 is replaced by "&a=x" format characters when the last one will not be deleted, you know we loop each time we are the new parameters on the last side.