如何在php中获取字符串的确切长度? [英] how to get the exact length of a string in php?
本文介绍了如何在php中获取字符串的确切长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的奇怪结果是:
strlen("òàùè")
如何正确计数带有 no-ascii 字符的字符串?
How can I count correctly string with no-ascii characters?
我也查看了mb_strlen(),但不能解决问题.
I also looked at mb_strlen() but does not solve the problem.
谢谢
推荐答案
mb_strlen
将
返回字符串$ str中的字符数.字符编码为$ encoding .一个多字节字符计为1.
Return the number of characters in string $str having character encoding $encoding. A multi-byte character is counted as 1.
您的内部编码可能未设置为utf-8,所以
Your internal encoding is likely not set to utf-8, so do
echo mb_strlen('òàùè', 'utf8');
或全局设置utf8:
mb_internal_encoding('utf8');
然后做
echo mb_strlen("òàùè");
会给出4(演示)
这篇关于如何在php中获取字符串的确切长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文