PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/phputf8/stristr.php

https://github.com/dianaprajescu/joomla-framework
PHP | 35 lines | 13 code | 5 blank | 17 comment | 4 complexity | b7cff1a0c0113fd82c4164e1a9269d9f MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @package utf8
  4. */
  5. //---------------------------------------------------------------
  6. /**
  7. * UTF-8 aware alternative to stristr
  8. * Find first occurrence of a string using case insensitive comparison
  9. * Note: requires utf8_strtolower
  10. * @param string
  11. * @param string
  12. * @return int
  13. * @see http://www.php.net/strcasecmp
  14. * @see utf8_strtolower
  15. * @package utf8
  16. */
  17. function utf8_stristr($str, $search) {
  18. if ( strlen($search) == 0 ) {
  19. return $str;
  20. }
  21. $lstr = utf8_strtolower($str);
  22. $lsearch = utf8_strtolower($search);
  23. //JOOMLA SPECIFIC FIX - BEGIN
  24. preg_match('/^(.*)'.preg_quote($lsearch, '/').'/Us',$lstr, $matches);
  25. //JOOMLA SPECIFIC FIX - END
  26. if ( count($matches) == 2 ) {
  27. return substr($str, strlen($matches[1]));
  28. }
  29. return FALSE;
  30. }