★ wanayoo — archive 1999 http://www.php.net/manual/function.str-repeat.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Strings
Quick Reference
German version of this pageJapanese version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
Strings
* AddCSlashes
* AddSlashes
* bin2hex
* Chop
* Chr
* chunk_split
* convert_cyr_string
* count_chars
* crc32
* crypt
* echo
* explode
* flush
* get_html_translation_table
* get_meta_tags
* hebrev
* hebrevc
* htmlentities
* htmlspecialchars
* implode
* join
* levenshtein
* ltrim
* md5
* Metaphone
* nl2br
* ob_start
* ob_get_contents
* ob_end_flush
* ob_end_clean
* ob_implicit_flush
* Ord
* parse_str
* print
* printf
* quoted_printable_decode
* quotemeta
* rtrim
* sscanf
* setlocale
* similar_text
* soundex
* sprintf
* strcasecmp
* strchr
* strcmp
* strcspn
* strip_tags
* stripcslashes
* stripslashes
* stristr
* strlen
* str_pad
* strpos
* strrchr
* str_repeat
* strrev
* strrpos
* strspn
* strstr
* strtok
* strtolower
* strtoupper
* str_replace
* strtr
* substr
* substr_count
* substr_replace
* trim
* ucfirst
* ucwords
Manual: str_repeat
View the source code for this pageSearch the site



Previous page
 strrchr
 Updated
Sat, 12 Aug 2000
strrev 
Next page


str_repeat

(PHP4 >= 4.0b4)

str_repeat -- Repeat a string

Description

string str_repeat (string input, int multiplier)

Returns input_str repeated multiplier times. multiplier has to be greater than 0.

Example 1. Str_repeat() example


echo str_repeat ("-=", 10);
     

This will output "-=-=-=-=-=-=-=-=-=-=".

Note: This function was added in PHP 4.0.


User Contributed Notes: str_repeat


dcac@usa.net
07-May-2000 08:07
<pre>function str_repeat($input, $mult)
{
$ret = "";
while ($mult > 0) {
$ret .= $input;
$mult --;
}
return $ret;
}
</pre>
should do the same thing




sshock@byu.edu
17-May-2000 12:08
I use it all the time in other programming languages. Like for instance, what if you wanted to output a bunch of lines to a file centered like this
These
will show up
really
nice
in here

You had to output a bunch of spaces on each line depending on the length of the line, so you could use this
fwrite($fp, str_repeat(" ", strlen($str)/2) . $str)
or something like that.........(p.s. yes I have lots of time on my hands....)



hahaha@yeahright.com
17-May-2000 07:06
It's mainly useful for formatting.

Things Like:

<pre>
apples: 1
pears: 2
oranges: 3
<pre>



robert@webmotion.com
28-Jun-2000 04:46
I use it for displaying data in arrays in a readable
format with indentation for nested data. ie.

function recurseDisplay( $data, $depth = 0 )
{
if( !is_array( $data ) )
return;

for( $i = 0; $i < count( $data ); $i++ )
{
echo "\n"
.str_repeat( ' ', $depth * 4 )
.$data[$i];
recurseDisplay( $data[$i], $depth + 1 );
}
}

Note: the above code is an example I didn't
bother to test it.



 About Notes


Previous page
 strrchr
 Updated
Sat, 12 Aug 2000
strrev 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.