fork download
  1. <?php
  2.  
  3. function match($mask, $name, $num) {
  4. if (empty($mask) and empty($name)) {
  5. return true;
  6. }
  7.  
  8. if (empty($name) != empty($mask)) {
  9. return false;
  10. }
  11.  
  12. if (!empty($mask) and !empty($name)) {
  13. // var_dump($mask, $name);
  14. // echo "\n";
  15. $pattern = mb_substr($mask, 0, 1);
  16. $tested = mb_substr($name, 0, 1);
  17. // var_dump($pattern, $tested);
  18. // echo "\n\n";
  19. if ($tested == $pattern or $pattern == "?") {
  20. return match(mb_substr($mask, 1), mb_substr($name, 1));
  21. } elseif ($pattern == "*") {
  22. $maskTail = mb_substr($mask, 1);
  23. for ($nameTail = $name; mb_strlen($nameTail) > 0; $nameTail = mb_substr($nameTail, 1)) {
  24. //var_dump ($maskTail, $nameTail);
  25. // echo "\n";
  26. if (match($maskTail, $nameTail)) {
  27. return true;
  28. break;
  29. }
  30. }
  31.  
  32. } else {
  33. return false;
  34. }
  35. }
  36. }
  37.  
  38. $tests = [ /*маска, имя, результат*/
  39. ["mask", "name", false],
  40. ["mask", "mask", true],
  41. ["test?", "test1", true],
  42. ["?test?", "1test3", true],
  43. ["??es?t?", "1tes2t3", true],
  44. ["?22??33", "1224433", true],
  45. ["t*t", "test", true],
  46. ["t*t", "test1", false],
  47. ["т*т?1", "те*?т21", true],
  48. ["*.txt", "book.txt", true],
  49. ["harry?.avi", "harry3.avi", true],
  50. ["*t*", "t", true],
  51. ["*t*", "starship", true],
  52. ["???", "st", false],
  53. ["*x", "xox", true],
  54. ["*", "", true],
  55. ["?", "", false],
  56. ];
  57.  
  58. for ($i=0; count($tests) > $i; $i++) {
  59. $a = (string) $tests[$i][2];
  60. echo "сравниваем ( {$tests[$i][0]} и {$tests[$i][1]} ) ожидаем увидеть: $a \n";
  61. if (match($tests[$i][0], $tests[$i][1]) == $tests[$i][2]) {
  62. echo "подошло\n";
  63. } else {
  64. echo "!!АЛЯРМ!! не подошло!! СБОЙ ПРОГРАММЫ\n";
  65. }
  66. echo "\n";
  67. }
  68.  
  69.  
  70.  
Success #stdin #stdout #stderr 0.02s 24400KB
stdin
Standard input is empty
stdout
сравниваем ( mask и name ) ожидаем увидеть:  
подошло

сравниваем ( mask и mask ) ожидаем увидеть: 1 
подошло

сравниваем ( test? и test1 ) ожидаем увидеть: 1 
подошло

сравниваем ( ?test? и 1test3 ) ожидаем увидеть: 1 
подошло

сравниваем ( ??es?t? и 1tes2t3 ) ожидаем увидеть: 1 
подошло

сравниваем ( ?22??33 и 1224433 ) ожидаем увидеть: 1 
подошло

сравниваем ( t*t и test ) ожидаем увидеть: 1 
подошло

сравниваем ( t*t и test1 ) ожидаем увидеть:  
подошло

сравниваем ( т*т?1 и те*?т21 ) ожидаем увидеть: 1 
подошло

сравниваем ( *.txt и book.txt ) ожидаем увидеть: 1 
подошло

сравниваем ( harry?.avi и harry3.avi ) ожидаем увидеть: 1 
подошло

сравниваем ( *t* и t ) ожидаем увидеть: 1 
!!АЛЯРМ!! не подошло!! СБОЙ ПРОГРАММЫ

сравниваем ( *t* и starship ) ожидаем увидеть: 1 
!!АЛЯРМ!! не подошло!! СБОЙ ПРОГРАММЫ

сравниваем ( ??? и st ) ожидаем увидеть:  
подошло

сравниваем ( *x и xox ) ожидаем увидеть: 1 
подошло

сравниваем ( * и  ) ожидаем увидеть: 1 
!!АЛЯРМ!! не подошло!! СБОЙ ПРОГРАММЫ

сравниваем ( ? и  ) ожидаем увидеть:  
подошло

stderr
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 62 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 62 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 62 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 62 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 62 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 62 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 62 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 62 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 62 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 62 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 62 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 62 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 62 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 62 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 62 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 27 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 21 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 62 and defined in /home/pd15Bw/prog.php on line 4
PHP Warning:  Missing argument 3 for match(), called in /home/pd15Bw/prog.php on line 62 and defined in /home/pd15Bw/prog.php on line 4