#33374 [NEW]: strval does not let me convert numbers to 'zero filled' strings

From: Date: Fri, 17 Jun 2005 00:26:17 +0000
Subject: #33374 [NEW]: strval does not let me convert numbers to 'zero filled' strings
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-80497@lists.php.net to get a copy of this message
From: tiago dot freire at gmail dot com Operating system: GNU/Linux PHP version: 5.0.4 PHP Bug Type: Feature/Change Request Bug description: strval does not let me convert numbers to 'zero filled' strings Description: ------------ Suppose I want to build a string with fixed length (for whatever reason) by appending a number to a string. //I want strings like 'foo0001','foo0002','foo0010' etc for ($i=1;$i<1000;$i++) { $string = 'foo'.$i; } strval could be useful IF it accepted a second (int) parameter to tell it: "This number will have <int parameter> characters in string form,fill it to the left with zeroes" With this behaviour,this would work: for ($i=1;$i<1000;$i++) { $string = 'foo'.strval($i,4);//This would give me '0001' } What about floats? Another parameter. Explained by example: for ($i=1;$i<1000;$i++) { $string = 'foo'.strval($i,4,3);//This would give me '0001.000' } For completeness: $number = 123456789; $string = 'bignumber: '.strval($number,5); Will result in the string 'bignumber123456789', since I asked for less characters than the number has. -- Edit bug report at http://bugs.php.net/?id=33374&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=33374&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=33374&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=33374&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=33374&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=33374&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=33374&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=33374&r=needscript Try newer version: http://bugs.php.net/fix.php?id=33374&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=33374&r=support Expected behavior: http://bugs.php.net/fix.php?id=33374&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=33374&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=33374&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=33374&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=33374&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=33374&r=dst IIS Stability: http://bugs.php.net/fix.php?id=33374&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=33374&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=33374&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=33374&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=33374&r=mysqlcfg

« previous php.bugs (#80497) next »