- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
// Released Under Affero General Public License, Version 3 (AGPL3)
// Author: [email protected]
$result = "TRUE";
$testable_string = strtolower($string_to_test);
$testable_string_length = strlen($string_to_test);
for($i_string = 0; $i_string < $testable_string_length; $i_string++)
{
$current_value_to_test = $testable_string[$i_string];
if( ($current_value_to_test != "0") &&
($current_value_to_test != "1") &&
($current_value_to_test != "2") &&
($current_value_to_test != "3") &&
($current_value_to_test != "4") &&
($current_value_to_test != "5") &&
($current_value_to_test != "6") &&
($current_value_to_test != "7") &&
($current_value_to_test != "8") &&
($current_value_to_test != "9") &&
($current_value_to_test != "a") &&
($current_value_to_test != "b") &&
($current_value_to_test != "c") &&
($current_value_to_test != "d") &&
($current_value_to_test != "e") &&
($current_value_to_test != "f") )
{
$result = "FALSE";
$i_string = $testable_string_length;
}
}
Смахивает на баян, но тем не менее.
http://php.net/manual/ru/function.is-numeric.php, из комментов.
> Affero
"affer" - "более утвердительный"?
1. Собственная реализация strtolower и strlen (не отдельной функцией)
2. $i_string = $testable_string_length; -> $i_string = $testable_string_length+1000; (для верности)
3. Использовать ASCII коды вместо строк в условии. (со всеми вытекающими)
4. Добавить именам еще информативности.
PS.
$Result строкой не плох.
Насколько мне известно, эту порнографию можно было одной регуляркой заменить.