Home > Article > Backend Development > How to Remove Specific Characters from the End of a String in PHP?
One common task in string manipulation is removing specific characters from the end of a string. For instance, you may need to delete a period if it's the final character.
Let's consider an example:
$string = "something here."; $output = "something here";
To remove a specific character from the end of a string, you can use the rtrim function. This function removes any trailing characters specified in its second argument from the input string.
In the given example, to remove a period from the end of the string, you can use:
$output = rtrim($string, '.');
This operation would assign the trimmed string to the $output variable, resulting in:
$output = 'something here';
The above is the detailed content of How to Remove Specific Characters from the End of a String in PHP?. For more information, please follow other related articles on the PHP Chinese website!