怎么判断一个字符传里面有没有中文? 楼上正解,字符的ASCII码值>255,就应该是中文 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //这样行吗function checkchinese(theelement){//如果含有中文字符返回 true text="abcdefghijklmnopqrstuvwxyz1234567890 ABCDEFGHIJKLMNOPQRSTUVWXYZ,/()!@$%&\#*~.;'_-<table>"; for(i=0;i<=theelement.length-1;i++) { char1=theelement.charAt(i); index=text.indexOf(char1); if(index==-1) { return true;//有中文 } //没有中文 } return false;} js<script>/*** 检查是否包含汉字 ***/String.prototype.isInChinese = function() { return (this.length != this.replace(/[^\x00-\xff]/g,"**").length);}s = "adsfasd你好asdfasdf";if(s.isInChinese()) alert("有汉字");</script>php<?php$s = "adsfasd你好asdfasdf";if(preg_match("/[\x80-\xff]./",$s)) echo "有汉字";?> <?php$s = "adsfasd你好asdfasdf";if(preg_match("/[\x80-\xff]./",$s)) echo "有汉字";?>此法最好 清單的值怎傳去文字欄位 php中定义的一次浏览器的session cookie在asp页里可以调用吗? 后台管理系统操作日志功能原理 PHP 基础问题 如何选择运行环境???? 有用过BEESCMS的吗请教一问题 PHP连sqlserver2000数据库连不上? 分页问题 急!!! 一个取得字符串的难题 一个很菜的问题,,不好意思 有人试过php5的reflection吗 如何用正则匹配注释?
function checkchinese(theelement)
{//如果含有中文字符返回 true
text="abcdefghijklmnopqrstuvwxyz1234567890 ABCDEFGHIJKLMNOPQRSTUVWXYZ,/()!@$%&\#*~.;'_-<table>";
for(i=0;i<=theelement.length-1;i++)
{
char1=theelement.charAt(i);
index=text.indexOf(char1);
if(index==-1)
{
return true;//有中文
}
//没有中文
}
return false;
}
<script>
/*** 检查是否包含汉字 ***/
String.prototype.isInChinese = function() {
return (this.length != this.replace(/[^\x00-\xff]/g,"**").length);
}s = "adsfasd你好asdfasdf";
if(s.isInChinese())
alert("有汉字");
</script>php
<?php
$s = "adsfasd你好asdfasdf";
if(preg_match("/[\x80-\xff]./",$s))
echo "有汉字";
?>
$s = "adsfasd你好asdfasdf";
if(preg_match("/[\x80-\xff]./",$s))
echo "有汉字";
?>
此法最好