Search code examples
phpmoney-format

PHP: Remove whitespace from money_format


I'm using money_format to generate a string like 1,23€.

At first I'm using

setlocale(LC_MONETARY, 'de_DE.utf8');

If I use this:

money_format('%.2n', $1.23);

I'm getting this:

1,23 €

But I would like to get this:

1,23€

(without whitespace).

How can I do this?


Solution

  • use PHP str_replace

    str_replace(' €','€','1,23 €')
    

    or

    str_replace(' ','','1,23 €')
    

    str_replace function replaces some characters with some other characters in a string

    str_replace(find,replace,string)