最后使用带有特殊字符的PHP的substr()会产生问号 [英] Using PHP's substr() with special characters at the end results in question marks
本文介绍了最后使用带有特殊字符的PHP的substr()会产生问号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在PHP中使用substr()函数时,当最后一个字符是特殊字符(例如ë或)时,在字符串的末尾会出现一个问号(带有问号的正方形-取决于浏览器). ö,等等...
When I use the substr() function in PHP, I get an question mark (a square with a question mark - depending on the browser) at the end of the string when this last character was a special one, like ë or ö, etc...
$introtext = html_entity_decode($item->description, ENT_QUOTES, "UTF-8");
$introtext = substr($introtext, 0, 200);
我该如何逃避呢?
推荐答案
If your string has multibyte encoding (like UTF-8) does, you should use mb_substr
to avoid problems like this:
$introtext=mb_substr($introtext,0,200);
这篇关于最后使用带有特殊字符的PHP的substr()会产生问号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文