<?
function CheckStr($str)
{
for($i=0;$i<strlen($str);$i++)
{
if(ord(substr($str,$i,1))>0xa0)
{
$types=1;
}
}
return $types;
}
$String="!";
echo (CheckStr($String)==1)?"有":"无";
?>

解决方案 »

  1.   

    我运行了以上程序,但是不好使,怎么改String结果都是“无”
      

  2.   

    <?
    function CheckStr($str){
    $types = 0;
    for($i=0;$i<strlen($str);$i++){
    if(ord(substr($str,$i,1))>0xa0){
    $types=1;
    }
    }
    return $types;
    }
    $String="中";
    echo (CheckStr($String)==1)?"全角":"半角";
    ?>
    没有问题啊。楼主怎么测试的?
      

  3.   

    正则表达式
    $p = "/[\x81-\xfe]./"; //含有全角字符
    $p = "/^(?:[\x81-\xfe].)+$/"; //全是全角字符<?php
    $s = "全是 全角字符";
    $p = "/[\x81-\xfe]./"; //含有全角字符
    //$p = "/^(?:[\x81-\xfe].)+$/"; //全是全角字符
    if(preg_match($p,$s))
      echo "yes";
    else
      echo "no";
    ?>