PageRenderTime 194ms CodeModel.GetById 100ms app.highlight 2ms RepoModel.GetById 91ms app.codeStats 0ms

/libraries/phputf8/stristr.php

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