note 51170 added to function.substr

From: Date: Tue, 22 Mar 2005 15:29:37 +0000
Subject: note 51170 added to function.substr
Groups: php.notes 
Request: Send a blank email to php-notes+get-86786@lists.php.net to get a copy of this message
This is a function I wrote. You might think of using substr() for writing a function like this, which might be easier. I did it my own way: <?php function tomoney($x) { $x = strrev($x); $geld_strl = strlen($x); for($i=0; $i<$geld_strl; $i+=3) { if(@$x{$i} != null) $y[$i] = $x{$i}; if($geld_strl > $i+1) $y[$i] = $x{$i+1}.$y[$i]; if($geld_strl > $i+2) $y[$i] = $x{$i+2}.$y[$i]; } $y = array_reverse($y); return "&euro; ".implode(",",$y); } ?> Example: <?php tomoney(4334332432) // returns: &euro; 4,334,332,432 tomoney(1000) // returns: &euro; 1,000 ?> ---- Manual Page -- http://www.php.net/manual/en/function.substr.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51170 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51170&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51170&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51170&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51170&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51170&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51170&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#86786) next »