Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace Comma(,) with Dot(.) RegEx php

Tags:

regex

php

i am trying this code but i get this error: No ending delimiter '/' found

$form = " 2000,50";
$salary = preg_replace('/',', '.'/', $form); // No ending delimiter '/' found 
echo $salary;

I am not sure about the regex validation.

like image 365
daniel__ Avatar asked Jun 14 '11 16:06

daniel__


3 Answers

Regex is overkill for replacing just a single character. Why not just do this instead?

str_replace(',', '.', $form);
like image 182
BoltClock Avatar answered Nov 17 '22 16:11

BoltClock


$salary = preg_replace('/,/', '.', $form);

But yeah, you don't really want to match a pattern but a string which is constant, so simply use str_replace().

like image 6
Midas Avatar answered Nov 17 '22 14:11

Midas


You can simply use

str_replace(',','.',$form);
like image 3
ArtoAle Avatar answered Nov 17 '22 16:11

ArtoAle