note 90225 added to function.substr
| From: | sarayut_b at hotmail dot com | Date: | Sat, 11 Apr 2009 02:23:20 +0000 |
| Subject: | note 90225 added to function.substr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-153072@lists.php.net to get a copy of this message | ||
<?php
function comma_in_number($a){
$start = 0;
for($i =(strlen($a)-1); $i>-1; $i--){
if(substr($a,$i,1) == "."){$start = $i-1;}
}
$length = array();
$cnt = $start+1;
while($cnt>=0){$cnt = $cnt-3; array_push($length,$cnt); }
//var_dump($length);
for($i =0; $i <=strlen($a); $i++){
if(in_array($i,$length) && $i !== 0 ){$new.= ",".substr($a,$i,1);} else {$new.=
substr($a,$i,1);}
}
return $new;
}
$a = "129582527.36"
$new = comma($a);
echo $new;
echo "<br>".$a;
?>
----
Server IP: 203.121.145.123
Probable Submitter: 124.120.236.195
----
Manual Page -- http://www.php.net/manual/en/function.substr.php
Edit -- https://master.php.net/note/edit/90225
Del: integrated -- https://master.php.net/note/delete/90225/integrated
Del: useless -- https://master.php.net/note/delete/90225/useless
Del: bad code -- https://master.php.net/note/delete/90225/bad+code
Del: spam -- https://master.php.net/note/delete/90225/spam
Del: non-english -- https://master.php.net/note/delete/90225/non-english
Del: in docs -- https://master.php.net/note/delete/90225/in+docs
Del: other reasons-- https://master.php.net/note/delete/90225
Reject -- https://master.php.net/note/reject/90225
Search -- https://master.php.net/manage/user-notes.php