Home >Backend Development >PHP Problem >What is the way to delete the last character in php
How to delete the last character in php: You can use the rtrim function to delete, such as [rtrim($str)]. The rtrim function can remove whitespace characters or other predefined characters on the right side of a string and return the modified string.
Function used:
rtrim() function removes blank characters or other predefined characters on the right side of the string and returns Modified string.
(Learning video recommendation: java video tutorial)
Example:
Remove spaces on the right side of the string:
<?php $str = "Hello World! "; echo "不使用 rtrim:" . $str; echo "<br>"; echo "使用 rtrim:" . rtrim($str); ?>
Remove the newline character (\n) on the right side of the string:
<?php $str = "Hello World!\n\n\n"; echo "不使用 rtrim:" . $str; echo "<br>"; echo "使用 rtrim:" . rtrim($str); ?>
Related recommendations: php training
The above is the detailed content of What is the way to delete the last character in php. For more information, please follow other related articles on the PHP Chinese website!