Home  >  Article  >  Backend Development  >  How to remove the comma on the right in php

How to remove the comma on the right in php

藏色散人
藏色散人Original
2021-05-25 09:46:411875browse

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.

How to remove the comma on the right in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn