php中正则匹配中文汉字
在php中如果你想正则来获取字符串中汉字我们先需要知道页面编码,正则匹配中文汉字根据页面编码不同而略有区别:GBK/GB2312编码:[x80-xff>]+ 或 [xa1-xff]+ 而UTF-8编码:[x{4e00}-x{9fa5}]+/u 。
例
代码如下 | 复制代码 |
echo (mb_eregi("[x80-xff].","中d文") ? "有" : "无") ."汉字"; |
以下以PHP为例进行匹配:
代码如下 | 复制代码 |
$str = "学习php是一件快乐的事。"; 输出: Array ) |
正则汉字
代码如下 | 复制代码 |
$str = "请问php中的eregi如何匹配汉字"; |
preg_match_all("/(汉字)+/ism","我是汉字,看你把我怎么着!",$m_a);
了各个编码的高位与低位的开始与结束,那么自然就可以写出正则,而且直接是十六位的,有啥困难?呵呵。不过要注意,在php里面,表示十六位是用的x
我们还可以用该正则表达式来判断是否是gb2312的汉字
代码如下 | 复制代码 |
$str = "小小子"; |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
