用星号替换整个字符串 [英] Replace whole string with stars

查看:130
本文介绍了用星号替换整个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种在PHP中用星号替换整个字符串的解决方案,例如,像这样的字符串:

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

测试

test123

test1234

并且取决于字符串的长度,它将用如下的星号替换字符串:

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

test的长度为4个字符,因此将被4个星标****代替.

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

test123的长​​度为7个字符,因此将被7个星标*******代替.等等...

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

有什么好的解决方案吗?

Is there any good solution for that?

推荐答案

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

简单地制作一个新的字符串,该字符串由所有星星组成,长度等于原始的长度.

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

这篇关于用星号替换整个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆