Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I replace commas with dot in the quoted sub-string only?

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"';
like image 490
Vyom Avatar asked Sep 05 '18 09:09

Vyom


Video Answer


1 Answers

You can do that using preg_replace

$string = preg_replace('/("\d+),(\d+")/','$1.$2',$string);
like image 141
Kerkouch Avatar answered Nov 03 '22 22:11

Kerkouch