【问题标题】:How can I hide/replace a part of a string in PHP? [duplicate]如何在 PHP 中隐藏/替换字符串的一部分? [复制]
【发布时间】:2021-07-06 19:45:42
【问题描述】:

我想使用我自己的函数隐藏字符串的一部分。例如:$string = "hello this is my password";。如果我的函数是 HashPartOfString($string),我想把我的字符串放在这个函数中,并得到这样的输出:hel***************ord。我该怎么做?

【问题讨论】:

标签: php string replace


【解决方案1】:

如果你总是想显示第一个和最后三个字母以及在一些 * 之间,你可以通过 sub-string 和 string concat 方法来做到这一点

$str = "hello this is my password"; 
echo substr($str,0,3)."******".substr($str,(strlen($str))-3,3);

【讨论】:

  • $str = "srfegkeruehkgu"; echo substr($str,0,3)."******".substr($str,(strlen($str))-3,3)
猜你喜欢
  • 2012-09-18
  • 2016-10-23
  • 2013-06-19
  • 2016-02-14
  • 2011-04-02
  • 2013-01-02
  • 1970-01-01
  • 2015-12-07
  • 1970-01-01
相关资源
最近更新 更多