0

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

$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
4

2 回答 2

1

怎么样:

$ReplaceAnswer = substr($Answer, 0, 1) . str_repeat('*', strlen($Answer) - 1);
于 2013-01-11T03:21:26.967 回答
1

这应该有效。

$tmp = preg_replace('/(?!^)[\S \t]/', '*', $inputstr);
于 2013-01-11T03:25:13.893 回答