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

前端 未结 5 1212
遇见更好的自我
遇见更好的自我 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:48

    I don't understand your parameters -- I'm not sure what's supposed to be in the string and what isn't. But for preg_replace, the search pattern should be a string, and with the string also begin and end with a delimiter (typically '/'). I think it's redudant to need slashes round the search string when it's already inside a string, but that's how it works.

    The second parameter should be a string containing the full stop and nothing else. This gives:

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

    Other people are correct that str_replace will be fine for turning one character into another, but if the replacement you want gets more complicated preg_replace will be reasonable.

提交回复
热议问题