note 15923 added to function.chunk-split
| From: | b1acksaber at hotmail dot com | Date: | Mon, 08 Oct 2001 23:35:37 +0000 |
| Subject: | note 15923 added to function.chunk-split | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-18703@lists.php.net to get a copy of this message | ||
In response to the hpaul@pikabaana.net, who wanted a function that "would separate numbers into
three number chunks 'backwards'." (ie: put commas into a number).
He came up with this long 15 line function to do it. Heres a Much easier way:
strrev(chunk_split(strrev($str), 3, ','))
that basicly... uses strrev to flip the string backward, then uses the above function on it, then
flips it foward again. Simple eh?
heres the function i made (it also removes the mark at the beggining)
function rev_chunk_split($str,$len=3,$end=','){
return substr(strrev(chunk_split(strrev($str),$len,$end)),1);
//rev_chunk_split('1234567',3,',') would return '1,234,567'
//(rev_chunk_split('1234567') would return the same thing)
}
--
http://www.php.net/manual/en/function.chunk-split.php
http://master.php.net/manage/user-notes.php?action=edit+15923
http://master.php.net/manage/user-notes.php?action=delete+15923
http://master.php.net/manage/user-notes.php?action=reject+15923