PHP 中使用 HTML 编号实体计算字符串长度
我想用PHP计算字符串的长度。该字符串包含 HTML 实体编号,这会增加计算的字符数:破折号是 –
,当我只想将其计为 1 时,它会计为 7。
我该如何做将html编号实体转换为特殊字符仅计算长度为1的形式?
示例字符串:
Goth-Trad – ‘Cosmos’
代码:
$string = html_entity_decode('Goth-Trad – ‘Cosmos’');
echo strlen($string);
当我查找“20”时,会生成“38”。出了什么问题?
I would like to count the length of a string with PHP. The string contains HTML entity numbers, which inflate the number of characters that are counted: a dash is –
which is counted as 7 when I only want it to count as 1.
How do I convert the html numbered entities to a form where special characters are only counted with a length of 1?
Example string:
Goth-Trad – ‘Cosmos’
The code:
$string = html_entity_decode('Goth-Trad – ‘Cosmos’');
echo strlen($string);
produces '38', when I'm looking for '20'. What is going wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可以使用这个:
You can use this:
就解码一下然后数解码的个数?
Just decode it and count the decoded one?
请尝试使用以下编码函数:
Please Try with the following coding function: