繁体   English   中英

排除html间距的计数

[英]Exclude count for html spacing

我有以下两个div标签,只想计算人类可读的单词/字符。

<div>Pickup</div>
<div>&nbsp;</div>

当我使用PHP strlen() ,它们都返回相同的值,而我不能使用它仅显示Pickup。 使用str_word_count()时的情况相同。

有任何想法吗?

首先,解码html实体并删除所有html标签:

$text = '<div>Pickup</div>';
echo strip_tags(html_entity_decode($text)); // This show up "Pickup" only

然后数词:

str_word_count($text); // This should return 1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM