Preg_replace(): No ending delimiter ',' found

Hi,
I am trying to preg_replace function but I am getting following error:
2019/11/07 22:08:53 [error] 1204#1204: *16 FastCGI sent in stderr: “PHP message: PHP Warning: preg_replace(): No ending delimiter ‘,’ found in /var/www/html/f_passbyref_p85.php on line 4” while reading response header from upstream, client: 127.0.0.1, se

<?Php
   //passing String to function by reference
   function stripCommas(&$inputString) {
      $inputString = preg_replace(",","", $inputString);
   }
   $myNumber = "10,000";
   
   stripCommas($myNumber);
   print($myNumber);
?>

Some body please guide me.

Zulfi.

<?php declare (strict_types = 1);

function stripCommas(&$inputString)
{
    $inputString = preg_replace("(,)", "", $inputString);
}
$myNumber = "10,000";

stripCommas($myNumber);
print($myNumber);
2 Likes

In all fairness though, preg_replace is overkill here. str_replace would work just as well, and faster.

2 Likes

Yes, for sure. I completely agree.

Hi,
Thanks a lot. God bless you.
It worked.
Zulfi.