Yet-Another-PHP-Framework /system/utf8/stristr.php

Language PHP Lines 50
MD5 Hash 813694edb1f15f0e68b6d55e0317dc60 Estimated Cost $329 (why?)
Repository https://github.com/avidenie/Yet-Another-PHP-Framework.git View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?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;
}
Back to Top