Try this one
$str = "this is. an example. 15.68€";
function cleaner($matches)
{
return str_replace("." , "," , $matches["nrs"]);
}
$str = preg_replace_callback ("/(?P<nrs>[0-9]+.[0-9]+)/" , "cleaner" , $str);
echo $str;
I have used preg_replace_callback
. The behavior of this function is almost identical to preg_replace()
, except for the fact that instead of replacement parameter, one should specify a callback. Check for more about it here. You can also test the live preview of my solution.
2
solved How can I replace dot with comma but only for numbers in a string ? (PHP) [duplicate]