Source for file RegexSearch.abstract.php

Documentation is available at RegexSearch.abstract.php

  1. <?php
  2. /**
  3. * @since 12/8/05
  4. * @package harmoni.osid_v2.repository.search
  5. *
  6. * @copyright Copyright &copy; 2005, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: RegexSearch.abstract.php,v 1.1 2005/12/08 20:12:41 adamfranco Exp $
  10. */
  11. require_once(dirname(__FILE__)."/SearchModule.interface.php");
  12.  
  13. /**
  14. * Abstract regular expression matching class that handles translation between
  15. * simple wildcard-based search strings and regular expression strings.
  16. *
  17. * @since 12/8/05
  18. * @package harmoni.osid_v2.repository.search
  19. *
  20. * @copyright Copyright &copy; 2005, Middlebury College
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  22. *
  23. * @version $Id: RegexSearch.abstract.php,v 1.1 2005/12/08 20:12:41 adamfranco Exp $
  24. */
  25. class RegexSearch
  26. extends SearchModuleInterface
  27. {
  28. /**
  29. * Translate a simple search string such as 'ge*ing' into a regex string such
  30. * as '/\<ge.*ing\>/i'
  31. *
  32. * @param string $simpleString
  33. * @return string
  34. * @access public
  35. * @since 12/8/05
  36. */
  37. function translateToRegex ($simpleString) {
  38. $simpleString = str_replace(
  39. chr(92),
  40. '\x5C',
  41. $simpleString);
  42. $searches = array(
  43. '/[\[\](){}\.\/|$^?]/',
  44. '/\*/'
  45. );
  46. $replacements = array(
  47. '\\\\\0',
  48. '.*'
  49. );
  50. return '/'.preg_replace($searches, $replacements, $simpleString).'/i';
  51. }
  52. }
  53.  
  54. ?>

Documentation generated on Wed, 19 Sep 2007 10:25:54 -0400 by phpDocumentor 1.3.0RC3