comma-formatting numbers

From: Date: Sat, 17 Nov 2001 21:36:19 +0000
Subject: comma-formatting numbers
Groups: php.general 
Request: Send a blank email to php-general+get-75010@lists.php.net to get a copy of this message
i'm new to php and am having difficulty translating this tiny awk function that i use to comma format numbers. can someone assist? my stumbling block thus far have been the fact the the php regex matching functions don't return the byte offset within the haystack and the regex replace functions don't support the awk and perl-like ampersand "&" in the replacement pattern. please help and thanks. function commas(num) { while (num ~ /[0-9][0-9][0-9][0-9]/) sub (/[0-9][0-9][0-9]$|[0-9][0-9][0-9][,]/, ",&", num) return num }

« previous php.general (#75010) next »