From: gphemsley at gmail dot com Operating system: PHP version: Irrelevant Package: Unknown/Other Function Bug Type: Feature/Change Request Bug description:Allow str_pad() to break 'both' tie on the left
Description: ------------ When using STR_PAD_BOTH with str_pad(), if there is a tie (i.e. an even/odd length mismatch), the tie will be broken using the default value: adding the string to the right. There should be a way to force str_pad() to break the tie to left, so that the left side has one more of the string than the right side. Perhaps add STR_PAD_BOTH_LEFT=3 and alias STR_PAD_BOTH=2 to STR_PAD_BOTH_RIGHT=2. Test script: --------------- <?php define( 'STR_PAD_BOTH_RIGHT', STR_PAD_BOTH ); // 2 define( 'STR_PAD_BOTH_LEFT', 3 ); echo str_pad( '2', 4, ' ', STR_PAD_RIGHT ) . "\n"; // '2 ' echo str_pad( '2', 4, ' ', STR_PAD_LEFT ) . "\n"; // ' 2' echo str_pad( '2', 4, ' ', STR_PAD_BOTH ) . "\n"; // ' 2 ' echo str_pad( '2', 4, ' ', STR_PAD_BOTH_RIGHT ) . "\n"; // ' 2 ' echo str_pad( '2', 4, ' ', STR_PAD_BOTH_LEFT ) . "\n"; // ' 2 ' ?> Expected result: ---------------- 2 2 2 2 2 Actual result: -------------- 2 2 2 2 Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in str_pad.php on line 10 -- Edit bug report at https://bugs.php.net/bug.php?id=62834&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=62834&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=62834&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=62834&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=62834&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=62834&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=62834&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=62834&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=62834&r=needscript Try newer version: https://bugs.php.net/fix.php?id=62834&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=62834&r=support Expected behavior: https://bugs.php.net/fix.php?id=62834&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=62834&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=62834&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=62834&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=62834&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=62834&r=dst IIS Stability: https://bugs.php.net/fix.php?id=62834&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=62834&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=62834&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=62834&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=62834&r=mysqlcfg