以下是alibaba里的一段判断输入文字是否是中文或英文的javascript,可以参考——要么同样也有javascript来判断,要么也可以改成PHP——反正语法有相近之处。
<script language="javascript">
var checkOk = new Array();
checkOk[0] = "12288";
checkOk[1] = "8364";
var win = null;function checkchi(myint) {
  
  var checkStr = myint;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {     ch = checkStr.charCodeAt(i);     if (ch > 256 && !isOkChar(ch))
    {      
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    return (false);
  }  return (true);}function isOkChar(ch)
{
for (j = 0;  j < checkOk.length;  j++)
       if (ch == checkOk[j])
       {
         return true;
        }
    return false;

}
function checkEncode(object,input_value)
  {   if (!(checkchi(input_value)))
   {
alert("Sorry, the information you filled is not in English. Please input in English instead."); object.focus();
return false;
   }
   return true;
  }
  
</script>

解决方案 »

  1.   

    我要作一个简单的在线词典,所以才问的~:)大家要见怪啊。
    最好是PHP判断的
      

  2.   

    http://aspxboy.com/private/showthread.asp?threadid=92
      

  3.   

    请问如何写匹配中文的正则表达式???  
    ---------------------------------------------------------------  
     
    $str  =  "中文测试";  
    preg_match_all("/([x81-xfe][x40-xfe])/",  $str,  $ch);  
    $patterns  =  array_unique($ch[0]);  
    print_r($patterns);
      from www.phpe.net