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

前端 未结 5 1201
遇见更好的自我
遇见更好的自我 2021-01-02 01:24

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

$form = \" 2000,50\";
$salary = preg_replace(\'/\',\', \'.\'/\', $f         


        
5条回答
  •  感情败类
    2021-01-02 01:50

    The '/' in your string is used as a start-of-regex delimiter so you need to escape it. The correct line should read:

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

    I'm also curious why the second param is ', ' . '/' rather than ', /'.

    EDIT

    Ahh I see now, the line should read:

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

    I was confused because the first comma in your example should be a '.' to concat the string.

提交回复
热议问题