Php regular expression meaning $ string & nbsp; preg_replace (& amp; (# (d {3, 5} | x [a-fA-F0-9] {4 }));), & nbsp; & amp; \ 1, str_replace (array (& amp;, & nbsp;, & nbsp; & lt;, & nbsp; & gt ;), & nbsp php regular expression meaning
$ String = preg_replace ('/& (# (\ d {} | x [a-fA-F0-9] {4});)/', '& \ 1 ',
Str_replace (array ('&', '"', '<', '>'), array ('&', '"', '<', '> '), $ string ));
Special characters in the escape string
'/& (# (\ D {3, 5} | x [a-fA-F0-9] {4});)/', '& \ 1', what does this mean?
------ Solution --------------------
Just take it apart.
Replace & # nnnnn or & # xnnnn with & # nnnnn
\ 1 indicates that the content in the first bracket is kept as is (# (\ d {3, 5}
------ Solution --------------------
X [a-fA-F0-9] {4}) this part
------ Solution --------------------
Reference:
$ String = preg_replace ('/& amp; (# (\ d {3, 5}
------ Solution --------------------
X [a-fA-F0-9] {4});)/',' & \ 1 ',
Str_replace (array ('&', '"', '<', '>'), array ('& amp;', '& quot;', '& lt; ',' & gt; '), $ str ......
This is the filter function of DISCUZ, right.
In fact, the consciousness of this function is to filter HTML strings, but those that have been filtered, such as "'" single quotation marks and double quotation marks. The "&" entity is. if it is like this, it is not filtered and retained to prevent multiple filters. Result & changed to & ampamp;
// Cancel the 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 ',
Str_replace (array ('&', '"', '<', '>', '\''), array (' & ',' "',' <', '>', '''), $ string ));
}
Return $ string;
}