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. BitmapFactory.decodeResource(res, id); 第一个参数跟第二个参数有什么关系?

    BitmapFactory.decodeResource(res, id); res= getResources();activity的方法 id = R.drawable.x  

  2. Circular placeholder reference 'server.port' in property definitions

    Exception in thread "main" java.lang.IllegalArgumentException: Circular placeholder refere ...

  3. LinGo:装货问题——线性规划,整数规划,1988年美国数模B题

    7种规格的包装箱要装有两辆铁路平板车上去,包装箱的宽和高相同,但厚度(t,以cm计)和重量(以kg计)不同, 表A-1给出了每包装箱的厚度.重量和数量,每辆车有10.2m长的地方用来装包装箱(像面包片 ...

  4. Robotium--scroll操作系列

    上下滚动 scrollDown public boolean scrollDown() Scrolls down the screen. Returns: true if more scrolling ...

  5. sqlcipher移植

    一.下载代码 sqlcipher赖openssl库,首先下载openssl: [fulinux@ubuntu ~]$ git clone https://github.com/openssl/open ...

  6. HNC-局部联想脉络

    局部联想脉络 概念分为:抽象概念.具体概念 对抽象概念用 五元组 和 语义网络 表达 对具体概念用 挂靠展开近似 表达 五元组:动态.静态.属性.值.效应.(u,g,u,z,r),用于表达抽象概念的外 ...

  7. Difference between Tomcat's extraResourcePaths and aliases to access an external directory--转

    Question: Simple question: In Tomcat7, what's the difference between using extraResourcePaths and al ...

  8. struts2,hibernate,spring整合笔记(1)

    今天终于配置好了ssh框架的整合,记录下过程供参考 环境:window8.1,jdk1.7 ,带有javaee的eclipse,也就是说要能发布web项目,TOMCAT服务器,tomcat配置涉及到环 ...

  9. ifconfig命令详解

    linux下网上命名规律:eth0,eth1.第一块以太网卡,第二块.lo为环回接口,它的IP地址固定为127.0.0.1,掩码8位.它代表你的机器本身. 1.ifconfig是查看网卡的信息 eth ...

  10. nginx 配置轮询服务

    通常我们应用nginx做代理时,用到它的轮训服务 #设置轮询名称 upstream zyy{ server 127.0.0.1:8080  #本机的apache服务 } server { listen ...