Home >Backend Development >PHP Problem >How to remove the last Chinese character in php
php method to remove the last Chinese character: first create a PHP sample file; then remove the last Chinese character through the "$newstr = substr($str,0,strlen($str)-3);" method Can.
Recommendation: "PHP Video Tutorial"
php removes the last character in the string and Chinese characters
1.php removes the last character in the string:
//方法一: $newstr = substr($str,0,strlen($str)-1); //方法二: $newstr = substr($str, 0, -1)
2.php removes the last Chinese character in the string:
//坑的地方就是这个,汉字在u8编码中是占3个字符,所以得注意 $newstr = substr($str,0,strlen($str)-3); //这是去掉字符串中的最后一个汉字
The above is the detailed content of How to remove the last Chinese character in php. For more information, please follow other related articles on the PHP Chinese website!