note 25275 added to function.str-repeat

From: Date: Tue, 17 Sep 2002 20:34:40 +0000
Subject: note 25275 added to function.str-repeat
Groups: php.notes 
Request: Send a blank email to php-notes+get-36855@lists.php.net to get a copy of this message
If you need an alternate str_repeat function that outputs an exact length using a particular input string to fill that length (as opposed to repeating the input string), try this little gem: <?php // use this function: function str_repeat2($input, $length) { // returns the output exactly $length using $input to fill that length $answer=""; if ($length>=1 && strlen($input)>=1) { $answer = substr(str_repeat($input, strlen($input) * ceil($length/strlen($input)) ), 0, $length); } return $answer; } //demo the function's use: $t="-=-"; print str_repeat2($t,0)."\n"; print str_repeat2($t,1)."\n"; print str_repeat2($t,2)."\n"; print str_repeat2($t,3)."\n"; print str_repeat2($t,4)."\n"; print str_repeat2($t,5)."\n"; print str_repeat2($t,6)."\n"; ?> -- http://www.php.net/manual/en/function.str-repeat.php http://master.php.net/manage/user-notes.php?action=edit+25275 http://master.php.net/manage/user-notes.php?action=delete+25275 http://master.php.net/manage/user-notes.php?action=reject+25275

« previous php.notes (#36855) next »