php method to remove the comma on the right: First create a PHP sample file; then use the "rtrim($str, ',');" method to delete the comma on the right in the string.
The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer
First explain each separately,
trim filters both ends of the string,
rtrim filters the tail of the string, =chop()
ltrim filters the beginning of the string.
Filters the key in the string You can only use str_replace.
As an example,
PHP code
The code is as follows:
$str = '123,333,234,'; echo rtrim($str, ',');
rtrim example code 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) ?>
[Recommended learning: PHP video tutorial]
The above is the detailed content of How to remove the comma on the right in php. For more information, please follow other related articles on the PHP Chinese website!