Suppose I have a string:
$string = 'apple, cat, dog, "0,445",symphony, "0,454"';
What output I want is:
$string = 'apple, cat, dog, "0.445",symphony, "0.454"';
Suppose I have a string:
$string = 'apple, cat, dog, "0,445",symphony, "0,454"';
What output I want is:
$string = 'apple, cat, dog, "0.445",symphony, "0.454"';
You can do that using preg_replace
$string = preg_replace('/("\d+),(\d+")/','$1.$2',$string);
Please find work around for your requirement,
$string = 'apple, cat, dog, "0.445",symphony, "0,454"';
$array = str_replace('*comma*', ',', explode(',',preg_replace_callback('|"[^"]+"|', function ($matches) {return str_replace(',', '*comma*', $matches[0]);}, $string)));
foreach ($array as $key => $value) {
$array[$key] = str_replace(',', '.', $value);
}
$string = implode(",", $array);
Try this regular expression : https://regexr.com/3uvj0
$string = preg_replace('/(\".)(,)(.*\")/', '$1.$3', $string);