ID: 43829
Comment by: public dot chris at web dot de
Reported By: l dot nanetti at rug dot nl
Status: Open
Bug Type: Strings related
Operating System: windows
PHP Version: 5.2.5
New Comment:
isn' t a bug. browser shows just one space. look at the source.
use the following code using htmlentities
$mystring = 'Luca Nanetti';
$formatstring = "[%30s]";
$fstring = sprintf($formatstring, $mystring);
$fstring = str_replace(' ', ' ', $fstring);
echo $fstring;
or replace echo $fstring; by following
echo '<pre>' . $fstring . '</pre>';
Previous Comments:
------------------------------------------------------------------------
[2008-01-13 19:46:55] l dot nanetti at rug dot nl
Description:
------------
what I want to do: left-padding a string with spaces.
In this example, up to 30 charachters.
code snippet:
<?php
$mystring = 'Luca Nanetti';
$formatstring = "[%30s]";
$fstring = sprintf($formatstring, $mystring);
echo $fstring;
?>
expected:
[ Luca Nanetti]
what I get is instead a one-charachter padding, i.e. the string
is left padded with only one space:
[ Luca Nanetti]
it successfully works with the number 0:
using "[%030s]" I get [000000000000000000Luca Nanetti]
it successfully works with custom padding, "[%'#30s]"
Additional informations:
- Abyss web server, accessed locally on 127.0.0.1:8000
- modules: PDO, PDO_SQLITE, MCRYPT
Reproduce code:
---------------
<?php
$mystring = 'Luca Nanetti';
$formatstring = "[%30s]";
$fstring = sprintf($formatstring, $mystring);
echo $fstring;
?>
Expected result:
----------------
[ Luca Nanetti]
Actual result:
--------------
[ Luca Nanetti]
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=43829&edit=1