Home > Backend Development > PHP Problem > How to remove the last character from php string

How to remove the last character from php string

藏色散人
Release: 2023-03-04 17:18:02
Original
2750 people have browsed it

How to delete the last character in a php string: First create a PHP sample file; then use the "substr($str,0,strlen($str)-1);" method to delete the last character in the specified string Just delete the last character.

How to remove the last character from php string

Recommended: "PHP Video Tutorial"

php Remove the last character of the string

Original string 1,2,3,4,5,6,

Remove the last character ",", the final result is 1,2,3,4,5,6

The code is as follows:

$str = "1,2,3,4,5,6,"; 
$newstr = substr($str,0,strlen($str)-1); 
echo $newstr; 
//echo 1,2,3,4,5,6
Copy after login

The function that comes with the system can achieve this effect, two methods:

substr($str, 0, -1)
//函数2
rtrim($str, ",")
Copy after login

The above is the detailed content of How to remove the last character from php string. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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