Home > php教程 > php手册 > 中文验证函数(php javascript)

中文验证函数(php javascript)

WBOY
Release: 2016-06-13 09:54:46
Original
1228 people have browsed it

中文字符判断是根据字符串编码来的,/^[chr(0xa1)-chr(0xff)]+$这就是判断是否为中文的php验证正则表达式 下面来看一个验证中文实例

中文字符判断是根据字符串编码来的,/^[chr(0xa1)-chr(0xff)]+$这就是判断是否为中文的php教程验证正则表达式
下面来看一个验证中文实例


$str = "一聚教程网";
if (preg_match("/^[".chr(0xa1)."-".chr(0xff)."]+$/", $str)) {
echo "这是一个纯中文字符串";
} else {
echo "这不是一个纯中文字串";
}

js

var str = "php编程";
if (/^[u4e00-u9fa5]+$/.test(str)) {
alert("该字符串全部是中文");
} else {
alert("该字符串不全部是中文");
}

php

if($en_utf8)
{    $joid = preg_replace("[^0-9a-za-z_-|x4e00-x9fa5|:|/|#|.]","",$joid);             }   //utf-8的中文匹配
else
{    $joid = preg_replace("[^0-9a-za-z_-|".chr(0xa1)."-".chr(0xff)."|:|/|#|.]","",$joid);   }   //gb2312的中文匹配


php中来判断字符串是否为中文,就会沿袭这个思路:

$str = "php编程";
if (preg_match("/^[u4e00-u9fa5]+$/",$str)) {
print("该字符串全部是中文");
} else {
print("该字符串不全部是中文");
}
?>

 

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template