note 15923 deleted from function.chunk-split by jimw
| From: | jimw@php.net | Date: | Mon, 08 Oct 2001 23:40:00 +0000 |
| Subject: | note 15923 deleted from function.chunk-split by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-18704@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)
}