My code is:
preg_replace('/[中]/', '1', '中,博文大,精中深');
Why the result is:
111,博文大,精111深
The Chinese character '中' should be replace once, while triple instead.
Any help? Thanks
My code is:
preg_replace('/[中]/', '1', '中,博文大,精中深');
Why the result is:
111,博文大,精111深
The Chinese character '中' should be replace once, while triple instead.
Any help? Thanks
First of all, please read this article about unicode characters in regexps.
Next, you may need this article about modifiers. I think that you need u
modifier in your regexp.
preg_replace('/[中]/u', '1', '中,博文大,精中深');
Please, also read comments in modifiers article for more examples.
Also, for simple replaces like in example above you can use str_replace.
str_replace('中', '1', '中,博文大,精中深');