Replace the whole chain with stars

I need a solution to replace a whole string with stars in PHP, for example, there are strings like:

Test

test123

test1234

And depending on the length of the string, it will replace the string with asterisks, like:

testhas a length of 4 characters, so it will be replaced by 4 stars ****.

test123has 7 characters, so it will be replaced with 7 stars *******. Etc...

Is there a good solution for this?

+3
source share
1 answer
$string = str_repeat('*', strlen($string));

Just create a new line, consisting of all the stars, with a length equal to the original.

+18
source

All Articles