Meaning of the PHP regular expression
$string = Preg_replace ('/& (# (\d{3,5}|x[a-fa-f0-9]{4});)/', ' &\\1 ',
Str_replace (Array (' & ', ' ' ', ' < ', ' > '), Array (' & ', ' "', ' < ', ' > '), $string));
Escape special characters in a string
'/& ((# (\d{3,5}|x[a-fa-f0-9]{4}));)/', ' &\\1 ', which part of the meaning?
------Solution--------------------
Just disassemble and understand.
Then replace the & #nnnnn or & #xnnnn with & #nnnnn
\\1 indicates that the contents of the first parenthesis are preserved as-Is ((# (# (# (\d{3,5}
------Solution--------------------
X[A-FA-F0-9]{4})) This part
------Solution--------------------
References:
$string = preg_replace ('/& (# (# (\d{3,5}
------Solution--------------------
X[A-FA-F0-9]{4}));)/', ' &\\1 ',
Str_replace (Array (' & ', ' ' ', ' < ', ' > '), Array (' & ', ' " ', ' < ', ' > '), $str
...
This is Discuz's filter function, right.
In fact, the consciousness of this function is to filter the HTML strings, but those that have already been filtered, such as "'" "single quotes double quotes." The "&" entity is & so like this is not filtered, reserved, in case of multiple filtering. The results & became &amp;
Canceling HTML code
function Shtmlspecialchars ($string) {
if (Is_array ($string)) {
foreach ($string as $key = = $val) {
$string [$key] = Shtmlspecialchars ($val);
}
} else{
$string = Preg_replace ('/& (# (# (\d{3,5}
------Solution--------------------
X[A-FA-F0-9]{4})
------Solution--------------------
[A-za-z] [A-z0-9] {1,5});) /', ' &\\1 ',
Str_replace (Array (' & ', ' ' ', ' < ', ' > ', ' \ '), Array (' & ', ' "', ' < ', ' > ', '), $string));
}
return $string;
}