note 52620 deleted from function.strrev by aharvey

From: Date: Mon, 10 Sep 2012 01:24:15 +0000
Subject: note 52620 deleted from function.strrev by aharvey
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-190603@lists.php.net to get a copy of this message
Note Submitter: avarab at gmail dot com ---- strrev() can be very useful in cases where it makes more sense to do something from the end of a string rather than the beginning (well duh!) such as apply certain regular expressions. Here's a small function to add commas to numbers that works in such a way. <?php echo commafy("1500000.1254"); // prints 1,500,000.1254 function commafy($_) { return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,' , strrev( $_ ) ) ); } ?> I originally wrote it in Perl, does it show? ;=)

« previous php.notes (#190603) next »