$str1="私は音楽が上手です"。
$str2="我擅长おんがく"。
其中$str1为纯日语,$str2为中日混合。如果用php进行判断该怎样做呢? 

解决方案 »

  1.   

    通过POST发送后,非日语字符,会被浏览器转成UNICODE,就是#加数字的形式。
    另外,用iconv进行转化,遇到非日语的字符,默认会截断字符串。
      

  2.   

    谢谢LuciferStar。可我是个新手,能不能给点代码啊。
      

  3.   

    是啊,coolesting说的对。我现在要用两个分词工具对字符串分词,一个对中国语分词,另一个对日语分词。所以只有判断好了字符串是纯中国语还是纯日语,才能分词。
      

  4.   

    要对这些数据进行分词,应该很不容易。
    http://www.singlestudio.net.cn/cnjp/x/
    这个,我也是利用了另一个站点的数据才做出来的效果。
    凡是没有假名的,就是纯粹的中文汉字。
      

  5.   

            Dim kamei As String = "あ,い,う,え,お,か,き,く...." '定义一个字符串,保存所有假名
            Dim kameiSplit() As String = kamei.Split(",")
            For Each tempStr As String In kameiSplit
                If InStr(strtisiki, tempStr) <> 0 Then
                  flag = 1
                Dim str1 As String = strtisiki.ToString
                Dim strbytes As Byte() = Encoding.Default.GetBytes(str1)
                Dim str2 As String = Encoding.GetEncoding(932).GetString(strbytes)
                If str1 <> str2 Then
                        flag = 2
                    End If
                    Exit For
                Else
                     flag = 0
                End If
            Next
      

  6.   

    以上是vb.net中判断字符串是否是纯日语、纯中文、中日混合的一段代码,flag=1表示为日语、=2为中日混合、=3为纯中文。strtisiki是要进行判断的字符串。请问在php里面怎么实现啊?谢谢
      

  7.   

    不好意思刚才打错了个地方,应该是flag=0的时候表示全中文。
      

  8.   

    判断每个字的charcode应该可以
      

  9.   

    //来个实例 $stra = '我来自中国';              //判断为 chinese,  但后面加上$strb之后变为other 
    $strb = '私は音楽が上手です ';      //判断为 other $pat = "/^[\x80-\xff_a-zA-Z0-9]+$/"; 
    if( preg_match($pat,$stra) ) 
    echo 'chinese ...'; 
    else 
    echo 'other ... '; 
    //由此看来, 要切词之后一个个来匹配, 才分辨出是否纯中文,纯日文
      

  10.   

    首先感谢「骄傲青蛙」的回复。该方法的确可以判断字符串是否是纯中文(在这里只要字符串中没有假名就算是纯中文,不考虑中文中有日语汉字)。但是怎样才能判断出字符串是中日文混合的呢?比如有字符串$str="请问济南钢铁集团生产「でんしゃ」吗?",这是个中日混合的字符串,在该字符串中除了"でんしゃ",其他的全是中文。用php该怎样判断呢?谢谢!
      

  11.   

    如果上面的思路不行, 你上google搜索 “中文分词”,“分词技术”
      

  12.   


    csdn上也有http://blog.csdn.net/liuzongshun/archive/2009/05/26/4216403.aspx
      

  13.   

    世界上有“纯日语”这种东西吗?
    ==========================================================
    欢迎加入以google wave为交流工具的PHP讨论组: [email protected] 
    加入办法: 
    1。 从你的gmail可以直接发信到 [email protected] 
    2。 PM你的邮箱给我,我直接加入 
    3。 到http://groups.google.com/group/phpwave/subscribe?note=1申请 
      如果该网址不能访问请尝试 https://groups.google.com/group/phpwave/subscribe?note=1 
          或 http://groups.google.co.uk/group/phpwave/subscribe?note=1 ...(或换其它国家域名) 
      

  14.   

    <?php
    $mydata="Excel中有一列数据是用公式求出来的,怎样才能把这一列数据拷贝出来。Eclipse中,JSP文件的Java代码无语法着色,怎么解决呢?";
    // do the segment
    $ignore=true; //定义清除标点符号的变量$ignore
    $cws = scws_new();
    $cws->set_ignore($ignore);//清除标点符
    //scws_set_charset('gbk');
    $cws->set_charset('utf8');
    // use default dictionary & rules
    $cws->send_text($mydata);
    echo $mydata."<br>";
    echo "<hr>";
    $res = $cws->get_result();
    print_r($res);
    echo"<hr>";
    $res = $cws->get_result();
    print_r($res);
    echo"<hr>";
    $res = $cws->get_result();
    print_r($res);die;    while ($res = $cws->get_result())
        {
         //print_r($res);
         //echo"<hr>";
            //foreach ($res as $tmp)
            //{        if(count(explode("n",$tmp['attr']))>1)    
             //       printf("%s/%s", $tmp['word'], $tmp['attr']);
                //    print "&nbsp;&nbsp;&nbsp;";
             //}
             foreach ($res as $a=>$tmp)
             { 
              echo "<font color= red>".$a."</font>";
              echo "<hr color=green width =88 align=left>";
              foreach($tmp as $aa=>$as)
                 
              {
                 echo $as."--";
              
              }
             echo "<br>";
             }
            flush();
        }
        echo"<hr size=9>";
    print_r($res);
    $cws->close();
    ?>
      

  15.   

    <?php
    error_reporting(0);
    $dbconn = pg_connect("host=localhost port=5432 dbname=test1 user=postgres password=ryouka") or die("can not connect the database"); 
    pg_query("set names UTF8");$file_name="Test_1.txt";
     $fp=fopen($file_name,'r');
     while(!feof($fp))
     {
       //echo"<hr>";
      $buffer=fgets($fp,4096);
      //$buffer=addslashes($buffer);
      $a=explode("---",$buffer);
      $xx=trim($a[0]);
      $yy=trim($a[1]);
      $zz=trim($a[2]);
      //echo strlen($a[0]);
       pg_query("insert into thread (id,title,question) values('$xx','$yy','$zz')");
      
      //echo $a[0];
     }
     fclose($fp);
     
    $b=pg_query("select * from d") or die("<br>表d不存在,查询失败!".mysql_error());$sum=pg_num_rows($b);
    echo "总记录数".$sum."<br>";
    echo"<table border=1><tr>";
    echo"<td width=81 bgcolor=#FFBB77>知識ID</td>";
    echo"<td width=281 bgcolor=#FFBB77 align=center>知識全文</td>";
    //echo"<td>チーム</td>";
    //echo"<td>経験</td>";
    //echo"<td>学歴</td>";
    //echo"<td>問題大分類</td>";
    //echo"<td>問題小分類</td>";
    echo"<td width=181 bgcolor=#FFBB77 align=center>名前</td></tr>";
    //echo"<td>提出年月</td>";
    //echo"<td>アクセス数</td>";
    //echo"<td>記入状況</td>";
    //echo"<td>職務</td></tr>";
    //die;

    for($i=0;$i<400;$i++)
    {//echo "ok";
    $x=pg_fetch_array($b);
    if ($x[1]<>"")
    {
    echo"<tr><td width=81 bgcolor=#97CBFF><font color=red>$x[0]</font></td><td width=281><font color=#8F4586>$x[1]</font></td><td width=181>$x[6]</td></tr>";
    }
    }echo"</table>";pg_close();//echo $dbconn;
    ?>