PageRenderTime 40ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/functions/stristr.php

http://github.com/FSX/php-utf8
PHP | 32 lines | 13 code | 6 blank | 13 comment | 4 complexity | 978d30fddd50eabde3d3c79cfd6612a2 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. namespace utf8;
  3. /**
  4. * UTF-8 aware alternative to stristr.
  5. *
  6. * Find first occurrence of a string using case insensitive comparison.
  7. *
  8. * @package php-utf8
  9. * @subpackage functions
  10. * @see http://www.php.net/strcasecmp
  11. * @uses utf8_strtolower
  12. * @param string $str
  13. * @param string $search
  14. * @return int
  15. */
  16. function ifind($str, $search)
  17. {
  18. if (strlen($search) == 0)
  19. return $str;
  20. $lstr = toLower($str);
  21. $lsearch = toLower($search);
  22. preg_match('/^(.*)'.preg_quote($lsearch).'/Us', $lstr, $matches);
  23. if (count($matches) == 2)
  24. return substr($str, strlen($matches[1]));
  25. return false;
  26. }