note 17359 added to function.intval
| From: | chris at zeronexus dot com | Date: | Wed, 05 Dec 2001 18:40:50 +0000 |
| Subject: | note 17359 added to function.intval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-21646@lists.php.net to get a copy of this message | ||
Thought I'd come up with a function to display an integer with commas. And then I decided to
share..
// splits a string and inserts comma to create an integer look
function comma_int( $string )
{
$length = strlen( $string );
if( $length <= 3 )
{
return $string;
}
else
{
$loop_count = intval( ( $length / 3 ) );
$section_length = -3;
for( $i = 0; $i < $loop_count; $i++ )
{
$sections[$i] = substr( $string, $section_length, 3 );
$section_length = $section_length - 3;
}
$stub = ( $length % 3 );
if( $stub != 0 )
{
$sections[$i] = substr( $string, 0, $stub );
}
return implode( ",", array_reverse( $sections ) );
}
}
--
http://www.php.net/manual/en/function.intval.php
http://master.php.net/manage/user-notes.php?action=edit+17359
http://master.php.net/manage/user-notes.php?action=delete+17359
http://master.php.net/manage/user-notes.php?action=reject+17359