/system/utf8/stristr.php
PHP | 50 lines | 17 code | 6 blank | 27 comment | 5 complexity | 813694edb1f15f0e68b6d55e0317dc60 MD5 | raw file
- <?php
- /**
- * This file is part of the Yet Another PHP Framework package.
- * (c) 2010 Adrian Videnie <{@link mailto:avidenie@gmail.com avidenie@gmail.com}>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- *
- * @package Framework
- * @subpackage I18n
- * @author Adrian Videnie <avidenie@gmail.com>
- * @copyright 2010 Adrian Videnie
- * @license http://www.opensource.org/licenses/mit-license.php The MIT license
- */
- /**
- * Multi-byte aware version of stristr native PHP function.
- *
- * Case-insenstive UTF-8 version of strstr. Returns all of input string
- * from the first occurrence of needle to the end.
- *
- * @see http://php.net/stristr
- * @author Harry Fuecks <hfuecks@gmail.com>
- *
- * @param string The input string.
- * @param string The needle.
- * @return mixed The matched substring if found, false either wise.
- */
- function _stristr($str, $search)
- {
- // If everything is ASCII, use the native PHP implementation.
- if (Utf8::isAscii($str) && Utf8::isAscii($search)) {
- return stristr($str, $search);
- }
- if ('' == $search) {
- return $str;
- }
- $str_lower = mb_strtolower($str);
- $search_lower = mb_strtolower($search);
- preg_match('/^(.*?)' . preg_quote($search, '/') . '/s', $str_lower, $matches);
- if (isset($matches[1])) {
- return substr($str, strlen($matches[1]));
- }
- return false;
- }