PHP Questions Home

Categories

Arrays
Files
Forms
Functions
Images
MySQL
Numbers
Others
Strings
Website


PHP Functions

PHP Functions


More PHP

Top Questions
Ask a Question

How can I repeat a string variable several times?


When you want to tell someone how much you love them but can't be bothered to type it, how can you get PHP to take the strain for you?

Solution: use the str_repeat function of course! Just tell it what you want to repeat and how many times and it'll do the work for you, like so:

<?php
$bemine 
"I love you lots ";
echo 
"$bemine" str_repeat("and LOTS ",10);
?>


Giving us this touching declaration:

I love you lots and LOTS and LOTS and LOTS and LOTS and LOTS and LOTS and LOTS a
nd LOTS and LOTS and LOTS



More strings PHP Questions

How do I remove trailing whitespace from a string?
How do I fetch the meta tags from a webpage using PHP?
How do I count the number of words in my text?
How can I remove trailing space from a string?
How do I make the contents of a string lower case?