Php stru_替换;将所有字母替换为*减去第一个?

Php stru_替换;将所有字母替换为*减去第一个?,php,Php,我试图用星号替换给定字符串的所有字母,减去第一个字母。我试过这个: $AnswerArr = str_split($Answer); $AnswerCount = count($Answer); $Toreplace = $AnswerCount - 1; $ReplaceAnswer = str_replace($AswerArr['0'], "*", $Answer, $Toreplace); 但这不起作用,我必须使用正则表达式吗 使用提供的第一个答案: Warning: substr()

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

$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
那么:

$ReplaceAnswer = substr($Answer, 0, 1) . str_repeat('*', strlen($Answer) - 1);
这应该行得通

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

您必须检查答案是否至少有1个字符长,或者改用
max(0,strlen($answer)-1)
。你能公布你使用的确切代码吗?太好了!不过,正则表达式是如何工作的呢?我不知道它们的用法,也不知道如何使用check来构造(?!^),检查它是否不是第一个字符[\S\t]表示字符或数字、空白或制表符的任何组合。有关常规表达式的更多信息,请参阅此