Home >Backend Development >PHP Problem >How to remove the last character in php
php method to remove the last character: We can use the rtrim() function to remove the last character. The rtrim() function is used to remove blank characters or other predefined characters on the right side of a string and return the modified string. The usage method is as follows: [rtrim($str,"World!");].
rtrim() function removes whitespace characters or other predefined characters on the right side of a string and returns the modified string.
(Recommended tutorial: php graphic tutorial)
Syntax:
rtrim(string,charlist)
Parameters:
string Required. Specifies the string to check.
#charlist Optional. Specifies which characters are removed from a string.
(Video tutorial recommendation: php video tutorial)
Code implementation:
<?php $str = "Hello World!"; echo $str . "<br>"; echo rtrim($str,"World!"); ?>
Output result:
Hello World! Hello
The above is the detailed content of How to remove the last character in php. For more information, please follow other related articles on the PHP Chinese website!