PHP函数substr()错误 [英] PHP function substr() error

查看:164
本文介绍了PHP函数substr()错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用substr()时,我得到一个奇怪的字符

$articleText = substr($articleText,0,500);

我的输出为500个字符和-<-

我该如何解决?这是编码问题吗?我的语言是希腊语.

解决方案

substr 使用字节计数,而不是字符.

希腊语可能意味着您正在使用一些多字节编码,例如UTF-8-并且按字节计数对于这些而言并不是很好.

也许使用 mb_substr 可能会有所帮助,在这里:<专门为多字节编码创建了href ="http://www.php.net/manual/zh/ref.mbstring.php" rel ="noreferrer"> mb_* 函数.

When I use substr() I get a strange character at the end

$articleText = substr($articleText,0,500);

I have an output of 500 chars and � <--

How can I fix this? Is it an encoding problem? My language is Greek.

解决方案

substr is counting using bytes, and not characters.

greek probably means you are using some multi-byte encoding, like UTF-8 -- and counting per bytes is not quite good for those.

Maybe using mb_substr could help, here : the mb_* functions have been created specifically for multi-byte encodings.

这篇关于PHP函数substr()错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆