PHP中trim 会导致中文乱码的解决方案
程序员文章站
2022-05-30 23:42:52
...
function mb_rtrim($string, $trim, $encoding)
{
$mask = [];
$trimLength = mb_strlen($trim, $encoding);
for ($i = 0; $i < $trimLength; $i++) {
$item = mb_substr($trim, $i, 1, $encoding);
$mask[] = $item;
}
$len = mb_strlen($string, $encoding);
if ($len > 0) {
$i = $len - 1;
do {
$item = mb_substr($string, $i, 1, $encoding);
if (in_array($item, $mask)) {
$len--;
} else {
break;
}
} while ($i-- != 0);
}
return mb_substr($string, 0, $len, $encoding);
}
mb_internal_encoding("UTF-8");
$tag = "互联网产品、";
$encoding = mb_internal_encoding();
print_r(mb_rtrim($tag, "、",$encoding));
转载于:https://my.oschina.net/koloor/blog/1823319
上一篇: Mysql的数据表修改操作
下一篇: 对常见全局属性的总结分享