Home>Article>Backend Development> Detailed explanation of the use of PHP string regular replacement function preg_replace
PHPStringRegular replacementFunctionpreg_replace instructions, friends in need can refer to it.
1. preg_replace()
$msg = preg_replace("/和中间的部分 $msg = preg_replace("/<[^>]+>/", "", $msg); -----是删除<>和中间的内容
i (PCRE_CASELESS)
If this modifier is set, the characters in the pattern will match both upper and lower case letter.
s (PCRE_DOTALL)
If this modifier is set, the dotmetacharacter(.) in the pattern matches all characters, including newlines. Without this setting, newline characters are not included. This is equivalent to Perl's /s modifier. ExcludeCharacter classessuch as [^a] always match newlines, regardless of whether this modifier is set.
2. ereg() and eregi()
Note: The preg_match() function is usually a faster alternative than ereg()
eregi("36e9da139ae3d6036e9cff5e98f5aec9]+)>(.+)36cc49f0c466276486e50c850b7e4956",$data,$b)----Check whether there is a body tag in $data. If so, assign the parameter $b[0] and the middle part $b[1].
bool ereg ( string pattern, string string [, array regs] ) int eregi ( string pattern, string string, array [regs] )
eregi() is similar to ereg() and has the same usage. The difference is that ereg() is case-sensitive, while eregi() is case-independent.
The above is the detailed content of Detailed explanation of the use of PHP string regular replacement function preg_replace. For more information, please follow other related articles on the PHP Chinese website!