A little php to format numerical value as Swedish currency

So, you have a number which represents a price but you want it to be formatted as Swedish currency. There are different ways of doing this but not all of them are cross platform compatible. For example, php’s “money_format” doesn’t work on windows. I came up with this little piece of code that will do the trick.

This will insert a space every third character from the end of a string. So, 1000000 will be 1 000 000.


function makeCurrency($price) {
	$price_array = str_split(strrev($price), 3);
	$price_nice = strrev(implode(" ", $price_array));
	return $price_nice;
}