Home  >  Article  >  Backend Development  >  How to remove the last Chinese character in php

How to remove the last Chinese character in php

藏色散人
藏色散人Original
2020-08-17 10:28:443072browse

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.

How to remove the last Chinese character in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn