note 38225 deleted from function.preg-replace by didou

From: Date: Sun, 14 Dec 2003 21:41:12 +0000
Subject: note 38225 deleted from function.preg-replace by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-61953@lists.php.net to get a copy of this message
Note Submitter: tlang@halsoft.com ---- Comma Punctuation in Numbers Here's an easy way to add commas in the right places when formatting a number (for the US at least :-) $val = 12345678; $valWithCommas = $val; while (preg_match("/\d\d\d\d/", $valWithCommas)) { $valWithCommas = preg_replace("/(\d+)(\d\d\d)/", "$1,$2", $valWithCommas); } print $valWithCommas; Output is 12,345,678

« previous php.notes (#61953) next »