난 그냥 필자가 2 부에 대한 질문을 오해 실현,하지만이 부분을 하나의 작동 및 문제 2 시작하기에 좋은 도움이 될 것입니다 :
<?php
$errorMessage = false;
$attempts = 1;
$maxAttempts = 5;
function validates($string)
{
global $errorMessage; //tell this function to use global errormessage
if (strlen($string) > 10) {
$errorMessage = 'Exceeded String Length. Please ensure no more than 10 characters are entered';
return false;
}
preg_match('/\d+/', $string, $matches);
$extractedDigits = (isset($matches[0]) ? $matches[0] : 0);
if ($extractedDigits > 3) {
$errorMessage = 'Exceeded allowed number of digits. Please ensure no more than 3 digits are contained in the string';
return false;
}
$errorMessage = false;
return true;
}
$result = readline('please enter a valid string: ');
while (!validates($result) && $attempts < $maxAttempts) { //while fail validation and have attempted less than the max attampts
echo "\n";
echo '*******************************************';
echo "\n";
echo 'Attempts Left (' . ($maxAttempts - $attempts) . ')';
echo "\n";
$result = readline($errorMessage . '. Please try again: ');
$attempts++;
}
echo "\n";
echo '*******************************************';
echo "\n";
if ($attempts >= $maxAttempts) {
echo 'Failed, too many attempts';
} else {
echo "\n";
echo 'Success...';
echo "\n";
echo "\n";
echo $result;
echo "\n";
echo "\n";
}
echo "\n";
이 부분이 들어 그냥 확인을 조정할 필요를 기능 –