note 71054 added to function.sprintf
| From: | SWestrup at osu1 dot php dot net | Date: | Thu, 09 Nov 2006 19:46:34 +0000 |
| Subject: | note 71054 added to function.sprintf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-119568@lists.php.net to get a copy of this message | ||
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));
----
Server IP: 216.235.15.211
Probable Submitter: 216.138.194.169
----
Manual Page -- http://www.php.net/manual/en/function.sprintf.php
Edit -- https://master.php.net/note/edit/71054
Del: integrated -- https://master.php.net/note/delete/71054/integrated
Del: useless -- https://master.php.net/note/delete/71054/useless
Del: bad code -- https://master.php.net/note/delete/71054/bad+code
Del: spam -- https://master.php.net/note/delete/71054/spam
Del: non-english -- https://master.php.net/note/delete/71054/non-english
Del: in docs -- https://master.php.net/note/delete/71054/in+docs
Del: other reasons-- https://master.php.net/note/delete/71054
Reject -- https://master.php.net/note/reject/71054
Search -- https://master.php.net/manage/user-notes.php