note 71054 deleted from function.sprintf by cmb
| From: | cmb@php.net | Date: | Sun, 14 Jul 2019 11:21:09 +0000 |
| Subject: | note 71054 deleted from function.sprintf by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211566@lists.php.net to get a copy of this message | ||
Note Submitter: SWestrup
----
In response to Anonymous, who claimed that:
printf("[%s]\n", str_pad('Hello', 20));
and
printf("[%-20s]\n", 'Hello');
are the same thing: you've missed the point.
They're only the same when the amount of padding is a known constant. When its a variable (or
an expression), its often much more convenient to be able to write:
printf("[%-*s]\n", 3*$n+2, "Hello");
than what you have to go through now, which is either:
$t = 3*$n+2;
printf("[%-{$t}s]\n","Hello");
or
printf("[%s]\n", str_pad('Hello', 3*$n+2));