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

How to remove the last character from php string

藏色散人
藏色散人Original
2020-08-18 10:08:382701browse

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

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

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

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!

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