The problem is, in some cases, we should give: http://jb51.net?a=1
This kind of URL address appending parameter becomes: http://jb51.net?a=1&b=2
But how do you know that the same parameter name already exists? For example, in this case: http://jb51.net?a=1&a=2
This is not a big mistake, but the address bar doesn’t look good. Then what shall I do? Use the regular solution (originally I wanted to use PHP’s string processing to solve this problem, but later I think I need to learn about regularization, so I’ll use regular to do it)
The following is the background processing method I used to return to the previous page
$url = $_SESSION[‘BACKURL’];
if($get!=array())
foreach ($get as $k=>$g){
$URL. = ‘-‘. $K. ‘=’ $g; / / append all parameters to be appended first, whether they are repeated or not
If (count (expand (“& {$k} =”, $URL)) > 2) {/ / if the current URL string is divided by “& A =”, more than two split arrays are found, which indicates that the string has duplicate parameters
$url=preg_ Replace (“/ {$k} = [a-za-z0-9] * & /, ‘, $URL); / / regular replacement all” & A = x “is empty
}
}
unset($_SESSION[‘BACKURL’]);
$this->alert($msg,$url);
}
Simple explanation:
“/ {$k} = [a-za-z0-9] * & /” if we assume that $k is “a”, that is / a = [a-za-z0-9] * & / “
I don’t know if there is any misunderstanding. This means that the match starts with “a =”, followed by any combination of numbers and letters ([a-za-z0-9] *: it means any single number or alphabetic character, which can be understood as the repetition of the previous arbitrary character. For example, u * can be understood as: Uuuuuu… The number of u permutations is not limited, here * can be replaced by {0,}), and then followed by “&”.
This is a very simple example, but looking at the description of regular grammar on the Internet, I always feel that I can’t understand it. I don’t know whether it’s my understanding ability or the writer’s words are too profound.
In addition, the principle is very simple, http://jb51.net?a=1&a=2 When the “& A = x” format character is replaced, the last one will not be deleted. We should know that we put the new parameter at the end every time in our loop.