1. <?php
  2. /**
  3.  * AbyssWS Pattern Matching
  4.  * Function: abyss_pattern_match()
  5.  *
  6.  * Created by: Joshua H. (TRUSTAbyss)
  7.  */
  8.  
  9. function abyss_pattern_match($pattern, $string)
  10. {
  11. // Create an array with the characters to be converted.
  12. $replace = array('\\' => '\\\\', '/' => '\/', '\/' => '\/', '.' => '\.', '\.' => '\.', '+' => '\+', '\+' => '\+', '\*' => '\*', '*' => '.*', '\?' => '\?', '?' => '.', '$' => '\$', '\$' => '\$', '(' => '\(', '\(' => '\(', ')' => '\)', '\)' => '\)', '{' => '\{', '\{' => '\{', '}' => '\}', '\}' => '\}', '=' => '\=', '\=' => '\=', '!' => '\!', '\\!' => '\!', '<' => '\<', '\<' => '\<', '>' => '\>', '\>' => '\>', '|' => '\|', '\|' => '\|', ':' => '\:', '\:' => '\:', '\-' => '\-', '[!' => '[^', '^' => '\^', '\\^' => '\^', '[^' => '[^', '\[' => '\[', '\]' => '\]');
  13.  
  14. // Return TRUE or FALSE based on the response of the preg_match() function.
  15. return preg_match("/^".strtr($pattern, $replace)."$/i", $string);
  16. }
  17.  
  18.  
  19. // Here's a short example of this function. It's just like using the eregi() function
  20. // but instead you get to match Abyss Web Server's patterns.
  21.  
  22. // This pattern will match sub folders containing mp2, mp3, or mp4 files.
  23. $pattern = "/*/*.mp[2-4]";
  24.  
  25. // Here's a sample string to be compared.
  26. $string = "/folder/file.mp3";
  27.  
  28. if (abyss_pattern_match($pattern, $string)) // A match was found.
  29. {
  30. echo "Congratulations! This pattern was successfully found within the string";
  31. }
  32. else // No pattern match.
  33. {
  34. echo "Looks like the pattern didn't match.";
  35. }
  36. ?>