note 9450 added to sprintf

From: Date: Fri, 03 Nov 2000 19:59:42 +0000
Subject: note 9450 added to sprintf
Groups: php.notes 
Request: Send a blank email to php-notes+get-7349@lists.php.net to get a copy of this message
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 http://www.php.net/manual/function.sprintf.php

« previous php.notes (#7349) next »