从PHP中的字符串中删除逗号

I have the following string:

Input:

$str = "I want to remove only comma from this string, how ?";

I want to remove commas from $str, I'm new in programming and I don't understand how regex works.

Regex: (?<!\d)\,(?!\d)

(\,|\.) for matching exact either , or .

(?!\d) should not contains digits ahead.

(?<!\d) should not contains digit behind.

PHP code:

<?php

$str = "I want to remove only comma from this string, how. ? Here comma and dot 55,44,100.6 shouldn't be removed";
echo preg_replace("/(?<!\d)(\,|\.)(?!\d)/", "", $str);

Output:

I want to remove only comma from this string how ? Here comma 55,44,100 shouldn't be removed

use str_replace.

Example

$str = "I want to remove only comma from this string, how ?";
$str = str_replace(",", "", $str);  

Explaination

As you can see there is 3 arguments we pass in str_replace

  1. "," => this one is what you want to replace

  2. "" => this one is value that will replace first argument value. we pass blank so it will replace comma to blank

  3. this one is string where you want to replace.