Home >Backend Development >PHP Problem >How to remove the last character in PHP?
#How to remove the last character in PHP?
In PHP, you can use the "rtrim()" function to remove the last character. This function is used to delete blank characters or other characters at the end of a string. Its syntax is "rtrim(str,char) ", its parameter str represents the string to be operated on, and the parameter char represents the character to be removed.
Usage example
<?php $text = "\t\tThese are a few words :) ... "; $binary = "\x09Example string\x0A"; $hello = "Hello World"; var_dump($text, $binary, $hello); print "\n"; $trimmed = rtrim($text); var_dump($trimmed); $trimmed = rtrim($text, " \t."); var_dump($trimmed); $trimmed = rtrim($hello, "Hdle"); var_dump($trimmed); // 删除 $binary 末端的 ASCII 码控制字符 // (包括 0 - 31) $clean = rtrim($binary, "\x00..\x1F"); var_dump($clean); ?>
The above routine will output:
string(32) " These are a few words :) ... " string(16) " Example string " string(11) "Hello World" string(30) " These are a few words :) ..." string(26) " These are a few words :)" string(9) "Hello Wor" string(15) " Example string"
Recommended tutorial: " PHP tutorial》
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!