How to remove the last Chinese character in php

藏色散人
Release: 2023-03-04 15:50:02
Original
3121 people have browsed it

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)
Copy after login

2.php removes the last Chinese character in the string:

//坑的地方就是这个,汉字在u8编码中是占3个字符,所以得注意
$newstr = substr($str,0,strlen($str)-3);  //这是去掉字符串中的最后一个汉字
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!