Replace whole string with stars

2019-02-18 04:50发布

问题:

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

test

test123

test1234

And depends on string length, it will replace string with the stars like:

test has 4 characters in length so it will be replaced with 4 stars ****.

test123 has 7 characters in length so it will be replaced with 7 stars *******. And so on...

Is there any good solution for that?

回答1:

$string = str_repeat('*', strlen($string));

Simply make a new string, consisting of all stars, with length equal to the original.



标签: php replace