PHP判断字符串中是否含有中文

<?
$str = "测试中文";
echo $str;
echo "<hr>";
//if (preg_match("/^[".chr(0xa1)."-".chr(0xff)."]+$/", $str)) { //只能在GB2312情况下使用
//if (preg_match("/^[\x7f-\xff]+$/", $str)) { //兼容gb2312,utf-8 //判断字符串是否全是中文
if (preg_match("/[\x7f-\xff]/", $str)) { //判断字符串中是否有中文
echo "正确输入";
} else {
echo "错误输入";
}
?>

php怎么将中文利用正则表达式匹配出来

正则匹配中文汉字根据页面编码不同而略有区别:
GBK/GB2312编码:[x80-xff]+ 或 [xa1-xff]+
UTF-8编码:[x{4e00}-x{9fa5}]+/u $str = "账单123";
//GBK/GB2312使用:
preg_match_all("/[\x80-\xff]+/", $str, $chinese);
//UTF-8 使用:
//preg_match_all("/[\x{4e00}-\x{9fa5}]+/u", $str, $chinese);
print_r($chinese);

php中文匹配的更多相关文章

  1. trim(),正则表达式中文匹配

    ^[/u4E00-/u9FA5]+$ 匹配中文 验证Email地址:“^w+[-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$”  验证InternetURL:“^http://([ ...

  2. php 正则中文匹配

    汉字一定注意是gbk还是utf8编码 UTF-8匹配:在javascript中,要判定字符串是中文是很简朴的.比如:var str = "php编程";if (/^[\u4e00- ...

  3. python-re之中文匹配

    #coding=utf-8 import re import chardet#检测网页编码形式的模块 p = re.compile(r'\d+') print p.findall('one1two2t ...

  4. Android 正则表达式匹配汉字中文

    关于中文的正则表达式, 应该是^[\\u4E00-\\u9FFF]+$, 和论坛里常被人提起的^[\\u4E00-\\u9FA5]+$很接近需要注意的是论坛里说的^[\\u4E00-\\u9FA5]+ ...

  5. php 匹配替换中文

    1.匹配中文 $str = "中文“; preg_match_all("/[\x{4e00}-\x{9fa5}]+/u",$str,$match); 2.替换中文: 在所 ...

  6. python 2.7中文字符串的匹配(参考)

    #!/bin/env python #-*- coding:utf-8 -*- import urllib import os,sys,json import ssl context = ssl._c ...

  7. Hive 正则匹配函数 regexp_extract

    regexp_extract 语法:    regexp_extract(string subject,  string pattern,  int index) 返回值: string 说明:  将 ...

  8. es 修改拼音分词器源码实现汉字/拼音/简拼混合搜索时同音字不匹配

    [版权声明]:本文章由danvid发布于http://danvid.cnblogs.com/,如需转载或部分使用请注明出处 在业务中经常会用到拼音匹配查询,大家都会用到拼音分词器,但是拼音分词器匹配的 ...

  9. rails中文本匹配相似度gem包对比

    测试数据 ["美科学家发现人体新器官","科学家发现新器官"],["曝高云翔悉尼被捕","高云翔涉性侵被捕"],[&qu ...

随机推荐

  1. Spring Boot集成Jasypt安全框架

    Jasypt安全框架提供了Spring的集成,主要是实现 PlaceholderConfigurerSupport类或者其子类. 在Sring 3.1之后,则推荐使用PropertySourcesPl ...

  2. POJ2996 Help Me with the Game(模拟)

    题目链接. 分析: 简单模拟. #include <iostream> #include <queue> #include <cstdio> #include &l ...

  3. 最大流Dinic

    不断用BFS构造分层网络,用DFS增广.中途用取指的cur优化DFS. Dinic封装模板: #include <cstdio> #include <iostream> #in ...

  4. 将银行读卡设备读取到的身份证头像Bitmap属性转换成路径

    需求是这样的,在项目开发的时候要求读取身份证,读到身份证的所有信息(信息里面包括头像属性,类型是Bitmap的).然后服务器要求我传过去的头像信息是String类型的Uri路径. 这是读卡器读到的身份 ...

  5. Emacs添加主题插件(Win系统)

    Emacs添加主题插件(Win系统) */--> /* @licstart The following is the entire license notice for the JavaScri ...

  6. UVAlive11324 The Largest Clique(scc+dp)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=30726 [思路] 强连通分量+动归. 求scc后缩点,以scc中的 ...

  7. Two Sum 解答

    Question: Given an array of integers, find two numbers such that they add up to a specific target nu ...

  8. HTTP学习实验8-windows添加telnet功能

    Windows 添加telnet功能: 控制面板->(查看方式:小图标)->程序和功能->打开或关闭Windows功能->Telnet客户端 Telnet 设置: 打开cmd, ...

  9. finally与return

    finally关键字:和try块使用,一般做资源释放操作,比如关闭流.关闭数据库连接,释放锁. return:用于返回值. finally块可保证一定执行,当逻辑处理有返回值时,会首先执行finall ...

  10. SKTransition类

    继承自 NSObject 符合 NSObject(NSObject) 框架  /System/Library/Frameworks/SpriteKit.framework 可用性 可用于iOS 7.0 ...