有幾種方法可以去除PHP字符串的最后一個(gè)字符:
$str = "Hello World";
$str = substr($str, 0, -1);
echo $str; // 輸出: Hello Worl
$str = "你好,世界";
$str = mb_substr($str, 0, -1);
echo $str; // 輸出: 你好,世
$str = "Hello World";
$str = rtrim($str, $str[strlen($str)-1]);
echo $str; // 輸出: Hello Worl
$str = "Hello World";
$str = preg_replace("/.$/", "", $str);
echo $str; // 輸出: Hello Worl