Home > Backend Development > PHP Tutorial > PHP matches Chinese characters

PHP matches Chinese characters

WBOY
Release: 2016-08-08 09:20:50
Original
2163 people have browsed it

The Chinese character matching in java is [u4E00-u9FA5]. Naturally, after using this regular expression in PHP, the following error was reported:

Warning: preg_match_all():Compilation failed: PCRE does not support L, l, N {name}, U, or u at offset 6 in D:xampphtdocstestindex.php on line 7

Later I discovered that x represents hexadecimal in PHP. So I changed the regular expression to [x4E00-x9FA5], but the following error will still be reported:

Warning: preg_match_all(): Compilation failed: invalid UTF-8 string at offset 9 in
D:xampphtdocstestindex.php on line 7
It seems to be another regular expression problem. Finally, just change the regular expression to [x{4E00}-x{9FA5}].

Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above introduces the matching of Chinese characters in PHP, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template