This is due to the PCRE library returning an error code if the string contains bad UTF-8.If you want to catch characters, as well european, russian, chinese, japanese, korean of whatever, just :- use mb_internal_encoding('UTF-8');- use preg_replace('`...`u', '...', $string) with the u (unicode) modifier For further information, the complete list of preg_* modifiers could be found at : (and other preg-functions) return null instead of a string when encountering problems you probably did not think about! Public Record and Publicly Available Information16. Opening parentheses are counted from left to right (starting from 1) to obtain the number of the capturing subpattern.
Match 1 or 0 times Match exactly n times Match at least n times Match at least n but not more than m times More Special Character Stuff\t tab (HT, TAB)\n newline (LF, NL)\r return (CR)\f form feed (FF)\a alarm (bell) (BEL)\e escape (think troff) (ESC)3 octal char (think of a PDP-11)\x1B hex char\c[ control char\l lowercase next char (think vi)\u uppercase next char (think vi)\L lowercase till \E (think vi)\U uppercase till \E (think vi)\E end case modification (think vi)\Q quote (disable) pattern metacharacters till \EEven More Special Characters\w Match a "word" character (alphanumeric plus "_")\W Match a non-word character\s Match a whitespace character\S Match a non-whitespace character\d Match a digit character\D Match a non-digit character\b Match a word boundary\B Match a non-(word boundary)\A Match only at beginning of string\Z Match only at end of string, or before newline at the end\z Match only at end of string\G Match only where previous m//g left off (works only with /g) Be aware that when using the "/u" modifier, if your input text contains any bad UTF-8 code sequences, then preg_replace will return an empty string, regardless of whether there were any matches.
use "my_processing_function('\1')" or something similar as replacement expression, and do the fixing in that function).
If you surrounded your backreference by single-quotes, the double-quotes are corrupt:$text = str_replace('\"', '"', $text); People using preg_replace with /e should at least be aware of this.
So when you use a backreference in the replacement expression, you need to put the backreference inside quotes, or otherwise it would be interpreted as PHP code.
Like the example from the manual for preg_replace:preg_replace("/()/e", "'\1'.strtoupper('\2').'\3'", $html_body); To make this easier, the data in a backreference with /e is run through addslashes() before being inserted in your replacement expression.