note 110326 added to function.sprintf
| From: | ignat dot scheglovskiy at gmail dot com | Date: | Wed, 10 Oct 2012 20:47:33 +0000 |
| Subject: | note 110326 added to function.sprintf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-191248@lists.php.net to get a copy of this message | ||
Here is an example how alignment, padding and precision specifier can be used to print formatted
list of items:
<?php
$out = "The Books\n";
$books = array("Book 1", "Book 2", "Book 3");
$pages = array("123 pages ", "234 pages", "345 pages");
for ($i = 0; $i < count($books); $i++) {
$out .= sprintf("%'.-20s%'.7.4s\n", $books[$i], $pages[$i]);
}
echo $out;
// Outputs:
//
// The Books
// Book 1.................123
// Book 2.................234
// Book 3.................345
?>
----
Server IP: 69.147.83.199
Probable Submitter: 81.163.131.63
----
Manual Page -- http://www.php.net/manual/en/function.sprintf.php
Edit -- https://master.php.net/note/edit/110326
Del: integrated -- https://master.php.net/note/delete/110326/integrated
Del: useless -- https://master.php.net/note/delete/110326/useless
Del: bad code -- https://master.php.net/note/delete/110326/bad+code
Del: spam -- https://master.php.net/note/delete/110326/spam
Del: non-english -- https://master.php.net/note/delete/110326/non-english
Del: in docs -- https://master.php.net/note/delete/110326/in+docs
Del: other reasons-- https://master.php.net/note/delete/110326
Reject -- https://master.php.net/note/reject/110326
Search -- https://master.php.net/manage/user-notes.php