Rev | Line | |
---|
[3] | 1 | <?php |
---|
| 2 | |
---|
| 3 | /** |
---|
| 4 | * @version $Id: stristr.php,v 1.1 2006/02/25 13:50:17 harryf Exp $ |
---|
| 5 | * @package utf8 |
---|
| 6 | * @subpackage strings |
---|
| 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 | */ |
---|
| 21 | function utf8_stristr($str, $search) |
---|
| 22 | { |
---|
| 23 | if (strlen($search) == 0) |
---|
| 24 | return $str; |
---|
| 25 | |
---|
| 26 | $lstr = utf8_strtolower($str); |
---|
| 27 | $lsearch = utf8_strtolower($search); |
---|
| 28 | preg_match('/^(.*)'.preg_quote($lsearch).'/Us', $lstr, $matches); |
---|
| 29 | |
---|
| 30 | if (count($matches) == 2) |
---|
| 31 | return substr($str, strlen($matches[1])); |
---|
| 32 | |
---|
| 33 | return false; |
---|
| 34 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.