note 9450 deleted from function.sprintf by derick
| From: | derick@php.net | Date: | Tue, 16 Mar 2004 10:51:05 +0000 |
| Subject: | note 9450 deleted from function.sprintf by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-66904@lists.php.net to get a copy of this message | ||
Note Submitter: david@marlinmedia.com
----
Here is a hack I came up with to center text. It's not perfect but it works well for
fixed-sized text.
$zone = 72; // size of zone to center in
$lsig = strlen($text_string);
$rspc = intval(($zone - $lsig) / 2);
$lspc = $zone - $lsig - $rspc;
$sstr = "%".$lspc."s%s%".$rspc."s";
sprintf($sstr," ",$text_string," ");
-or-
sprintf("%".($zone - (strlen($text_string)) - (intval(($zone - (strlen($text_string))) /
2)))."s%s%".(intval(($zone - (strlen($text_string))) / 2))."s","
",$text_string," ");
David