Hi, I have an e-shop and i want to format my prices to this format 1350 -> 1.350 or 1548236 -> 1.548.236 is this possible with PHP?
Hello, use the below code, <?php function format_price($num){ $var=$num; $countlent=strlen($var); for($i=0;$i < $countlent;$i++){ if($i==0){ $streSUb=substr($var,0,1); $streSUb123=substr($var,1,$countlent); $strStore=$streSUb.".".$streSUb123; } if($i==3){ $streSUb=substr($strStore,0,5); $streSUb123=substr($strStore,5,$countlent); $strStore=$streSUb.".".$streSUb123; } if($i==6){ $streSUb=substr($strStore,0,9); $streSUb123=substr($strStore,9,$countlent); $strStore=$streSUb.".".$streSUb123; } } echo $strStore; } format_price(12345678); ?>
thanks my friend but i found a very shorter way <?php setlocale(LC_MONETARY, 'el_GR'); echo money_format('%.2n', $row['price']); ?> PHP: this is the result "1.350,00€"