首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP希伯来字符计数

PHP希伯来字符计数
EN

Stack Overflow用户
提问于 2014-11-04 09:56:11
回答 1查看 798关注 0票数 1

还有检查希伯来语字符数的吗? language.Following是代码片段

代码语言:javascript
复制
<?php
 $e_str="This is football";// 3 words
 $h_str="זה כדורגל";//hebrew translation of above
 $h_str= trim(addslashes($h_str)); 
echo 'English Count :  '.str_word_count(mb_convert_encoding($e_str, 'HTML-ENTITIES', 'ISO-8859-1')).'<br/>';//prints 3

echo 'Hebrew Count :  '.str_word_count(html_entity_decode(mb_convert_encoding($h_str,'HTML-ENTITIES','UTF-8'),ENT_QUOTES,'UTF-8'));//prints zero
?>

也许我应该把希伯来语的计数定为“2”,而不是零。有解决办法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-06 15:34:04

尝试将其拆分为一个空格并计数数组长度。

代码语言:javascript
复制
echo 'Hebrew Count :  '.count(explode(' ', html_entity_decode(mb_convert_encoding($h_str,'HTML-ENTITIES','UTF-8'),ENT_QUOTES,'UTF-8')));//prints 2
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26732193

复制
相关文章

相似问题

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