首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在字符串php中检测除英语以外的其他语言?

如何在字符串php中检测除英语以外的其他语言?
EN

Stack Overflow用户
提问于 2016-12-21 22:04:37
回答 1查看 199关注 0票数 2

如何在字符串php中检测除英语以外的其他语言?

我使用这个代码来检测除英语之外的其他语言。

我想知道如何缩短我的代码,并涵盖所有语言。

代码语言:javascript
复制
<?PHP
$utf8_str = "xxxxxxxxxxxxxxx";
$Common = preg_match("/\p{Common}+/u", $utf8_str);
$Arabic = preg_match("/\p{Arabic}+/u", $utf8_str);
$Armenian = preg_match("/\p{Armenian}+/u", $utf8_str);
$Bengali = preg_match("/\p{Bengali}+/u", $utf8_str);
$Bopomofo = preg_match("/\p{Bopomofo}+/u", $utf8_str);
$Braille = preg_match("/\p{Braille}+/u", $utf8_str);
$Buhid = preg_match("/\p{Buhid}+/u", $utf8_str);
$Canadian_Aboriginal = preg_match("/\p{Canadian_Aboriginal}+/u", $utf8_str);
$Cherokee = preg_match("/\p{Cherokee}+/u", $utf8_str);
$Cyrillic = preg_match("/\p{Cyrillic}+/u", $utf8_str);
$Devanagari = preg_match("/\p{Devanagari}+/u", $utf8_str);
$Ethiopic = preg_match("/\p{Ethiopic}+/u", $utf8_str);
$Georgian = preg_match("/\p{Georgian}+/u", $utf8_str);
$Greek = preg_match("/\p{Greek}+/u", $utf8_str);
$Gujarati = preg_match("/\p{Gujarati}+/u", $utf8_str);


if(($Common != '0') OR ($Arabic != '0') OR ($Armenian != '0') OR ($Bengali != '0') OR ($Bopomofo != '0') OR ($Braille != '0') OR ($Buhid != '0') OR ($Canadian_Aboriginal!= '0') OR ($Cherokee != '0') OR ($Cyrillic != '0') OR ($Devanagari != '0') OR ($Ethiopic != '0') OR ($Georgian != '0') OR ($Greek != '0') OR ($Gujarati != '0'))
{
    echo "have other language";
}
else
{
    echo "Only english";
}
?>
EN

回答 1

Stack Overflow用户

发布于 2016-12-21 22:06:54

国际化比简单的正则表达式需要更多的时间。看看这个,https://lingohub.com/blog/2013/07/internationalization-how-to-5-most-popular-php-frameworks/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41264643

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档