dongliuxia9495 2014-06-05 01:20
浏览 195
已采纳

如何使用PHP语言检测字符串上的日文字符? [关闭]


Given the following 3 strings,

String 1 (Japanese with other language words):
"激安価格お買い得タイヨー脱腸帯·片側用 fm 腰回り with any other word"

String 2 (Portuguese):
"isto é um teste."

String 3 (English):
"This is a test"

How can I only identify the String 1 using PHP?

Thks in advance.

EDIT:
Since this topic is on hold, I'm gonna try to meet stackoverflow's requirements:

"This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself." – Anonymous, jeroen, Hanky 웃 Panky

I have a problem... :(
My problem is that I am receiving lots of Spam messages on a reviews system website. I've noticed that most of them has japanese characters. My bosses said specifically that I can't use any captcha mechanism.

So.... The only thing I can think of is detect japanese characters... like I've mentioned on the title, and described on the post!

Better?
Cheers! :)

  • 写回答

1条回答 默认 最新

  • doujie3888 2014-06-05 01:25
    关注

    http://ideone.com/s8Mzum

    I tried this on Ideone, works but isn't throughly tested though.

       <?php
    
    $word = "激安価格お買い得タイヨー脱腸帯·片側用 fm 腰回り";
    $word2 = "This is the english language";
    
    function isJapanese($lang) {
        return preg_match('/[\x{4E00}-\x{9FBF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}]/u', $lang);
    }
    
    var_dump(isJapanese($word)); //returns 1
    var_dump(isJapanese($word2));//returns 0
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化