Home >Backend Development >PHP Problem >How to remove the last character of a string in php
The way PHP removes the last character from a string is through the substr() function. The substr() function can return a part of a string. Function syntax: [substr(string, start, length)], if it fails, it returns FALSE.
php Deleting the last character of the string can be achieved through the substr() function and sublen() function.
(Recommended tutorial: php tutorial)
Related function introduction:
substr() function:
substr () function returns a portion of a string.
Syntax:
substr(string,start,length)
Return value:
Returns the extracted part of the string, returns FALSE if it fails, or returns an empty string.
Code implementation:
<?php $str = "1,2,3,4,5,6,"; $newstr = substr($str,0,strlen($str)-1); echo $newstr; //echo 1,2,3,4,5,6 ?>
The above is the detailed content of How to remove the last character of a string in php. For more information, please follow other related articles on the PHP Chinese website!