<?php
function match($mask, $name) {
return true;
// var_dump($mask, $name);
// echo "\n";
// var_dump($pattern, $tested);
// echo "\n\n";
if ($tested == $pattern or $pattern == "?") {
} elseif ($pattern == "*") {
//var_dump ($maskTail, $nameTail);
// echo "\n";
if (match($maskTail, $nameTail)) {
return true;
break;
}
}
} else {
return false;
}
} else {
return false;
}
}
$tests = [ /*маска, имя, результат*/
["mask", "name", false],
["mask", "mask", true],
["test?", "test1", true],
["?test?", "1test3", true],
["??es?t?", "1tes2t3", true],
["?22??33", "1224433", true],
["t*t", "test", true],
["t*t", "test1", false],
["т*т?1", "те*?т21", true],
["*.txt", "book.txt", true],
["harry?.avi", "harry3.avi", true]
];
for ($i=0; count($tests) > $i; $i++) { $a = (string) $tests[$i][2];
echo "сравниваем ( {$tests[$i][0]} и {$tests[$i][1]} ) ожидаем увидеть: $a \n";
if (match($tests[$i][0], $tests[$i][1]) == $tests[$i][2]) {
echo "подошло\n";
} else {
echo "!!АЛЯРМ!! не подошло!! СБОЙ ПРОГРАММЫ\n";
}
echo "\n";
}
PD9waHAKZXJyb3JfcmVwb3J0aW5nKC0xKTsKCmZ1bmN0aW9uIG1hdGNoKCRtYXNrLCAkbmFtZSkgewoJaWYgKGVtcHR5KCRtYXNrKSBhbmQgZW1wdHkoJG5hbWUpKSB7CgkJcmV0dXJuIHRydWU7Cgl9IGVsc2VpZiAoIWVtcHR5KCRtYXNrKSBhbmQgIWVtcHR5KCRuYW1lKSkgewoJCS8vCXZhcl9kdW1wKCRtYXNrLCAkbmFtZSk7CgkJLy8JZWNobyAiXG4iOwoJCSRwYXR0ZXJuID0gbWJfc3Vic3RyKCRtYXNrLCAwLCAxKTsKCQkkdGVzdGVkID0gbWJfc3Vic3RyKCRuYW1lLCAwLCAxKTsKCQkvLwl2YXJfZHVtcCgkcGF0dGVybiwgJHRlc3RlZCk7CgkJLy8JZWNobyAiXG5cbiI7CgkJaWYgKCR0ZXN0ZWQgPT0gJHBhdHRlcm4gb3IgJHBhdHRlcm4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