How to remove commas before and after in php

青灯夜游
Release: 2023-03-15 20:20:02
Original
2077 people have browsed it

Methods to remove commas before and after: 1. Use trim() to remove commas on both sides of the string at once, using the syntax "trim($str,",")"; 2. Use ltrim() to remove the string For the comma at the beginning, use rtrim() to remove the comma at the end. The syntax is "ltrim(rtrim($str,","),",")".

How to remove commas before and after in php

The operating environment of this tutorial: Windows 7 system, PHP version 7.1, DELL G3 computer

php remove the commas before and after Two methods

  • Use trim()

  • Use ltrim() rtrim()

1. Use the trim() function

trim() function can remove commas on both sides of the string at one time

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);   
$str = &#39;,1,2,3,4,5,6,&#39;;
echo trim($str,",");
?>
Copy after login

How to remove commas before and after in php

2. Use the ltrim() rtrim() function

  • ltrim() function can remove commas at the beginning of the string

  • rtrim() function can remove the comma at the end of the string

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);   
$str = &#39;,1,2,3,4,5,6,7,8,9,&#39;;
echo ltrim($str,",")."<br>";
echo rtrim($str,",")."<br>";
echo ltrim(rtrim($str,","),",");
?>
Copy after login

How to remove commas before and after in php

Recommended learning: "PHP Video Tutorial

The above is the detailed content of How to remove commas before and after in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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