原文作者: xingguang
原文链接:https://www.tiance.club/post/2735926554.html
调用代码
mb_internal_encoding("UTF-8");
$encoding = mb_internal_encoding();
$endData=self::mb_rtrim("广州市", "市",$encoding);
print_r($endData);exit;
原文作者: xingguang
原文链接:http://www.tiance.club/post/2735926554.html
封装方法
public static 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);
}
原文作者: xingguang
原文链接:http://www.tiance.club/post/2735926554.html