note 52620 added to function.strrev
| From: | avarab at gmail dot com | Date: | Sat, 07 May 2005 07:53:17 +0000 |
| Subject: | note 52620 added to function.strrev | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-89064@lists.php.net to get a copy of this message | ||
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? ;=)
----
Manual Page -- http://www.php.net/manual/en/function.strrev.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52620
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52620&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52620&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52620&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52620&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52620&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52620&report=yes
Search -- http://master.php.net/manage/user-notes.php