Utilities
|
|
|
|
<?php // 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 ) );
}
}
?>
|
|
|
Usage Example
|
$hits = 1234567;
echo comma_int( $hits );
|
|
|
Rate This Script
|
|
|
|