search
Homephp教程php手册PHP正确匹配UTF-8中文的正则

PHP正确匹配UTF-8中文的正则

Jun 13, 2016 am 10:50 AM
phpstringutf-8ChinesecodematchOKregularcorrectof

直接上代码吧
2 $string="你好啊,hello world";
3 preg_match('~[\x{4e00}-\x{9fa5}]+~u', $string, $array);

5  
6 print_r ( $array );
打印结果:
1 Array
2 (
3     [0] => 你好啊
4 )
注意 :编码是UTF-8的哦 GBK的不是这样写的.
作者:yangqijun

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools