php method to remove the last comma in a string: use the function rtrim to filter the end of the string, the code is [$trimmed = "\t\tThese are a few words :) .."$str = '13, 3';echo rtrim($str, ',')].
【Related learning recommendations: php graphic tutorial】
How to remove the last comma in a string in php:
First explain it separately,
trim filters both ends of the string,
rtrim filters the end of the string,=chop()
ltrim filters the beginning of the string.
To filter the keys in a string, you can only use str_replace
.
For example,
PHP code
The code is as follows:
$str = '123,333,234,'; echo rtrim($str, ','); rtrim实例代码2
The code is as follows:
<?php $text = "\t\tThese are a few words :) ... "; $trimmed = rtrim($text); // $trimmed = "\t\tThese are a few words :) ..." $trimmed = rtrim($text, " \t."); // $trimmed = "\t\tThese are a few words :)" $clean = rtrim($binary, "\x00..\x1F"); // trim the ASCII control characters at the end of $binary // (from 0 to 31 inclusive) ?>
Related learning recommendations:php programming(video)
The above is the detailed content of How to remove the last comma from a string in php. For more information, please follow other related articles on the PHP Chinese website!