Home > Backend Development > PHP Tutorial > PHP correctly matches UTF-8 Chinese regular expression_PHP tutorial

PHP correctly matches UTF-8 Chinese regular expression_PHP tutorial

WBOY
Release: 2016-07-13 17:52:21
Original
1023 people have browsed it

Just go to the code
1 2 $string="Hello, hello world";
3 preg_match('~[x{4e00}-x{9fa5}]+~u', $string, $array);
4
5
6 print_r ( $array );
Print result:
1 Array
2 (
3 [0] => Hello
4)
Note: The encoding is UTF-8. GBK is not written like this.
Author: yangqijun

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478128.htmlTechArticleGo directly to the code 1?php 2$string=Hello, hello world; 3preg_match(~[x{ 4e00}-x{9fa5}]+~u, $string, $array); 4 5 6print_r ( $array ); Print result: 1Array 2( 3 [0] = Hello...
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