This is my code:
<?php
$str1 = "Hello";
printf("[%99s]",$str1);
?>
I expect it to output 94 spaces as padding to fulfill the min length. Why does it only output 1 space to the right of the string?
This is my code:
<?php
$str1 = "Hello";
printf("[%99s]",$str1);
?>
I expect it to output 94 spaces as padding to fulfill the min length. Why does it only output 1 space to the right of the string?
If you're outputting to a web page, HTML doesn't see spaces (if you check the source code, the 94 spaces are probably present). You'd have to pad with ' '
.
Try this instead:
echo str_replace(' ', ' ', sprintf("[%-99s]
", $str1));