一,判断全是中文
复制代码 代码如下:
$str="'324是";
if(!eregi("[^\x80-\xff]","$str")){
echo "全是中文";
}else{
echo "不是";
}
二,判断含有中文
复制代码 代码如下:
$str = "中文";
if (preg_match("/[\x7f-\xff]/", $str)) {
echo "含有中文";
}else{
echo "没有中文";
}
或
$pattern = '/[^\x00-\x80]/';
if(preg_match($pattern,$str)){
echo "含有中文";
}else{
echo "没有中文";
}
我这几种方法都是在utf-8下面测试的,别的编码下没有测试过。
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
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
How to fix KB5055612 fails to install in Windows 10?
4 weeks agoByDDD
Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Roblox: Grow A Garden - Complete Mutation Guide
3 weeks agoByDDD
Nordhold: Fusion System, Explained
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools
