Search code examples
phpmoney-format

How to replace dot with comma in price format in php


I have a price format like 1.100.000 Now I want to replace all dots with comma so it should look like this- 1,100,000. To achieve this I tried this code-

<?php
$number=1.100.000;
$number=str_replace('.',',',$number);
?>

But it is not working. Can any one help.?


Solution

  • Missing the quotes.Try this -

    $number="1.100.000";
    $number=str_replace('.',',',$number);
    var_dump($number);
    

    OutPut -

    string(9) "1,100,000"