<?php
str str_repeat ( str $input , int $multiplier )
where,
$input = The input STRING to be repeated
$multipier = Number of times that the
input STRING will be repeated
?>
<?php
$str01 = "repeated words<br>";
$nbr01 = 6;
echo str_repeat($str01, $nbr01);
?>
<?php
echo "Testing str_repeat() with possible strings.<br>";
$variations = [
'a',
'foo',
'barbazbax',
"\x00",
'\0',
NULL,
TRUE,
4,
1.23,
"",
" "
];
/* variations in string and multiplier as an int */
foreach($variations as $input) {
echo "<br><br>str_repeat() of '$input':<br>" ;
for($n=0; $n<4; $n++) {
echo "<br>after repeating $n times is => ";
echo str_repeat($input, $n)."<br>";
}
}
echo "<br><br>Testing error conditions:<br>";
try {
str_repeat($input[0], -1);
// Invalid arg for multiplier
} catch (\ValueError $e) {
echo $e->getMessage() . "<br>";
}
?>
<?php
$str = chr(0).chr(128).
chr(129).chr(234).
chr(235).chr(254).chr(255);
$withCodePoint = str_repeat($str, chr(51));
// ASCII value of '3' given
$explicit = str_repeat($str, 3);
var_dump($withCodePoint === $explicit);
echo '<br><br>';
var_dump( bin2hex( $withCodePoint ) );
echo '<br><br>';
var_dump( bin2hex( $explicit ) );
?>