PageRenderTime 43ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/include/utf8/stristr.php

https://bitbucket.org/gencer/fluxbb
PHP | 34 lines | 12 code | 5 blank | 17 comment | 4 complexity | 67d952a30da9d79480db6c0601237715 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * @version $Id: stristr.php,v 1.1 2006/02/25 13:50:17 harryf Exp $
  4. * @package utf8
  5. * @subpackage strings
  6. */
  7. /**
  8. * UTF-8 aware alternative to stristr
  9. * Find first occurrence of a string using case insensitive comparison
  10. * Note: requires utf8_strtolower
  11. * @param string
  12. * @param string
  13. * @return int
  14. * @see http://www.php.net/strcasecmp
  15. * @see utf8_strtolower
  16. * @package utf8
  17. * @subpackage strings
  18. */
  19. function utf8_stristr($str, $search)
  20. {
  21. if (strlen($search) == 0)
  22. return $str;
  23. $lstr = utf8_strtolower($str);
  24. $lsearch = utf8_strtolower($search);
  25. preg_match('/^(.*)'.preg_quote($lsearch).'/Us', $lstr, $matches);
  26. if (count($matches) == 2)
  27. return substr($str, strlen($matches[1]));
  28. return false;
  29. }