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