note 17359 deleted from function.intval by zak

From: Date: Thu, 06 Dec 2001 11:35:56 +0000
Subject: note 17359 deleted from function.intval by zak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-21684@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 ) ); } }

« previous php.notes (#21684) next »