,大小写不敏感将所有字母替换为*减去第一个


str_replace; Replace all letters with a * Minus The First?

我试图用星号减去第一个字母替换给定字符串的所有字母。我试过了:

$AnswerArr = str_split($Answer);
$AnswerCount = count($Answer);
$Toreplace = $AnswerCount - 1;
$ReplaceAnswer = str_replace($AswerArr['0'], "*", $Answer, $Toreplace);

但这不起作用,我必须使用正则表达式吗?

使用提供的第一个答案:

Warning: substr() expects parameter 1 to be string, array given in /var/www/New/API/FormValidation.php on line 15
Warning: strlen() expects parameter 1 to be string, array given in /var/www/New/API/FormValidation.php on line 15
Warning: str_repeat() [function.str-repeat]: Second argument has to be greater than or equal to 0 in /var/www/New/API/FormValidation.php on line 15

应该可以。

$tmp = preg_replace('/(?!^)['S 't]/', '*', $inputstr);

如何:

$ReplaceAnswer = substr($Answer, 0, 1) . str_repeat('*', strlen($Answer) - 1);