note 74826 added to function.substr

From: Date: Sun, 29 Apr 2007 19:26:08 +0000
Subject: note 74826 added to function.substr
Groups: php.notes 
Request: Send a blank email to php-notes+get-125962@lists.php.net to get a copy of this message
I changed the fucntion created by chislam4444 at gmail dot com so that it is dynamic and the code is shorter. <? function add_commas($num){ $decimalpos = strpos($num, "."); if(!$decimalpos === false){ $startpos = $decimalpos; } else { $startpos = strlen($num); } $comma_string = $num; $startpos -= 3; for($a = $startpos; $a > 0; $a -= 3){ $comma_string = substr($comma_string, 0, $a) . "," . substr($comma_string, $a); } return $comma_string; } echo add_commas(30000); // 30,000 echo "<br>"; echo add_commas(300000); // 300,000 echo "<br>"; echo add_commas(3000000); // 3,000,000 ?> ---- Server IP: 216.235.15.211 Probable Submitter: 24.141.63.46 ---- Manual Page -- http://www.php.net/manual/en/function.substr.php Edit -- https://master.php.net/note/edit/74826 Del: integrated -- https://master.php.net/note/delete/74826/integrated Del: useless -- https://master.php.net/note/delete/74826/useless Del: bad code -- https://master.php.net/note/delete/74826/bad+code Del: spam -- https://master.php.net/note/delete/74826/spam Del: non-english -- https://master.php.net/note/delete/74826/non-english Del: in docs -- https://master.php.net/note/delete/74826/in+docs Del: other reasons-- https://master.php.net/note/delete/74826 Reject -- https://master.php.net/note/reject/74826 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#125962) next »