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

How to remove the comma on the right in php

藏色散人
Release: 2023-03-09 21:42:01
Original
1910 people have browsed it

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, ',');
Copy after login

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)
?>
Copy after login

[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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template