Ordinary string:
Original string: 1,2,3,4,5,6,
This string: 1,2,3,4,5,6, remove the last character ","
Remove the last character ",", the final result is 1,2,3,4,5,6
$str = "1,2,3,4,5,6,"; $newstr = substr($str,0,strlen($str)-1); echo $newstr;
Chinese character string:
Original string: Wuzhou City
Remove the last Chinese character "city" , the final result is Wuzhou (utf-8 encoding)
$get_city='梧州市'; $get_city=mb_substr($get_city,0,strlen($get_city)-3); echo $get_city;
The above introduces the use of PHP to remove the last character of a string with substr and mb_substr, including the content of substr. I hope friends who are interested in PHP tutorials can learn from it. help.