PHP replace string with asterisks “*”

Is there a quick and easy way to replace every letter of a word with an asterisk “*”

For example  
word -->becomes ****
longer becomes ******
verylongword beomes ************

Thanks in advance for your feddbak
Who is Participating?
theodorejsalvoConnect With a Mentor Commented:
Using preg_replace is an easy bet, and will help if you only want to change words, or if you want to change any characters...

// To Change any character
$text = "verylongword123";
$newText = preg_replace('@.@','*',$text);

// To change just letters
$text = "verylongword123";
$newText = preg_replace('@\w@','*',$text);

Alternatively, you could also str_repeat to put an asterisk for every character in the string

$text = "verylongword123";
$newText = str_repeat('*',strlen($text));
sabecsAuthor Commented:
Thanks Theodore for all the options, they are perfect.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.