就是逐个读取字串里的字符.判断这个字符ASCII码的范围是否合适. 英方字母的范围是'a'到'z'和'A'到'Z',数字是'0'到'9'.中文字占两个字节,繁体和简体的范围不同,但高字节的最高位都是1,也就是>0x7f,低字节可以不管,因为简体里最高位为1,而繁体不一定.

解决方案 »

  1.   

    我好象没有看过这方面的方法,我的方法是:
    for ($i=chr(ord(A)),$i<=chr(ord(z)),$i++)
    {
     $rersult1=ereg("$i",$string);
    }
    for ($i=0,$i<=9,$i++)
    {
    $result2=ereg("$i",$string);
    }
    $result3=ereg("-",$string);
    $result4=ereg("_",$string);
    if ($result&&$result2&&$result3&&$result4)
    {
    ...
    }
    第二个问题
    Array
    (
        [0] => Array
            (
                [0] => "a"
                [1] => "b"
                  ....
                [25]=>"z"
            )
        [1]=>Array
            (
                [0]=>"A"
                [1]=>"B"
                  ...
                [25]=>"Z"
             )
    )
    for ($i=0,$i<=1,$i++0
    {   
        for ($j=0,$j<=25,$j++)
         {
           $r=preg_split(Array[$i][$j],$string));
         reset($r);
         }
    }
    浅妄薄见,望与斟酌
      

  2.   

    我有个把GB网页源代码转为BIG5的,
    里有判断是字符还是汉字的。
    QQ:710055
      

  3.   

    对于第一个问题:
    可以用正则表达式来决定字符串中只允许有26个英文大小写均可,0~9数字,“_”“-”两个横杆:
    "^[a-zA-Z0-9_-]$"对于第二个问题:
    可以用php的扩展模块mbstring,即用来处理多字节字符的函数库,php自身带的有,不过默认并未安装。
    安装上用函数
    mb_substr可以安全的截取字符串,不会出现乱码
      

  4.   

    页面问题还是用js最好了
    用php台耽误服务器了
      

  5.   

    Q1:
    同wasy(嘻嘻哈哈) ,用正则判别,ereg函数即可Q2:
    别人给我的一个函数,比较好用
    // 中文串截取
    function substrgb($in,$start,$num=0){
    $in=str_replace(" "," ",$in);
    if($num == 0) $num = strlen($in);
        $pos=$start;  
        $out="";  
        while(($c=substr($in,$pos,1))||($c=='0')){  
    if($c=="\n") break;
    if(ord($c)>128){  
    $out.=$c;  
    $pos++;  
    $c=substr($in,$pos,1);  
    $out.=$c;  
    }  
    else{  
    $out.=$c;  
    }  
    $pos++;  
    if($pos>=$start+$num) break;  
      }  
      return $out;  
    }
      

  6.   

    我有个把GB网页源代码转为BIG5的,
    里有判断是字符还是汉字的。
    QQ:710055
    演示:http://gsp.d2g.com/temp/hh/gb2big5.php
    源:
    ------------gb2big5.php
    <font size=4><b>Make your GB file to Big5 file</b></font>&nbsp;&nbsp;&nbsp;
    <font size=2>Powered by zyme. Welcome to www.ipisu.com.</font><br><br>
    <form action='gb2bing5.php' method=post>
    The GB file:<input name='srcfile'>
    <input type=submit value='Make!'>
    </form>
    <?php //Powered by zyme //Welcome to www.ipisu.com
    if($srcfile!="")
    {
    ///////////////
    //----------------
    $mb_file="hc.tab";
    // $d_big5_er="^"; //use this modify line 36,37
    $gb_file=$srcfile;
    $big5_file=time()."big5_file";
    //----------------
    if(!fopen($gb_file,"r")){echo"<br><br><font color=red size=4>The $gb_file file is not ready!</font>";exit;}
    if(!fopen($mb_file,"r")){echo"<br><br><font color=red size=4>The $mb_file file is not ready!</font>";exit;}
    $mb_fl=file($mb_file);
    $gb_fl=file($gb_file);for($a=0;$gb_fl[$a];$a++)
    {
    $gb_fl[$a]=str_replace("charset=gb2312","charset=big5",$gb_fl[$a]);
    $gb_l_len=strlen($gb_fl[$a]);
    for($b=0;$b<=$gb_l_len;$b++)
    {
    $o_w=substr($gb_fl[$a],$b,1);
    if(ord($o_w)>128)
    {
    $o_w=substr($gb_fl[$a],$b,2);
    for($c=0;$mb_fl[$c];$c++)
    {
    if($o_w==substr($mb_fl[$c],0,2))
    {
    $n_w=substr($mb_fl[$c],2,2);
    //$n_w=substr($mb_fl[$c],2,-1); //user $d_big5_er
    //if(strlen($n_w)>2){$n_w=$d_big5_er.$n_w.$d_big5_er;} //user $d_big5_er
    break;
    }
    else if(!$mb_fl[$c+1])
    {
    $n_w=$o_w;
    }
    }
    $b++;
    }
    else
    {
    $n_w=$o_w;
    }
    $big5_fl[$a]=$big5_fl[$a].$n_w;
    }
    $big5_src=$big5_src.$big5_fl[$a];
    }
    //--------------
    $fp=fopen($big5_file,"w+");
    fwrite($fp,$big5_src);
    //--------------
    echo"<br><br>Complete!  <a href=$big5_file>Visit the big5 file now!</a>";
    ////////////////
    }
    ?>
    --------------hc.tab在http://gsp.d2g.com/temp/hh/hc.tab