Home > Article > Backend Development > How to delete a character in php
php method to delete a character: first create a PHP sample file; then define a variable; then delete the last character through the "substr($str,0,strlen($str)-1);" method That’s it.
The operating environment of this article: Windows 7 system, PHP version 5.6, DELL G3 computer.
php delete the last character
Original string 1,2,3,4,5,6,
Remove the last character", ", the final result is 1,2,3,4,5,6
Use the substr and strlen functions to achieve this.
Code:
$str = "1,2,3,4,5,6,"; $newstr = substr($str,0,strlen($str)-1); echo $newstr;
Recommended: "PHP Video Tutorial"
The above is the detailed content of How to delete a character in php. For more information, please follow other related articles on the PHP Chinese website!