Finds position of first occurrence of a UTF-8 string. This is a UTF8-aware version of strpos.
$position = UTF8::strpos($str, $search);
integer Core_UTF8::strpos( string $str , string $search [, integer $offset = integer 0 ] )
参数列表
参数 类型 描述 默认值 $str
string
Haystack $search
string
Needle $offset
integer
Offset from which character in haystack to start searching integer 0
integer
position of needleboolean
FALSE if the needle is not foundpublic static function strpos($str, $search, $offset = 0)
{
$offset = (int)$offset;
if (IS_MBSTRING) return mb_strpos($str, $search, $offset, Core::$charset);
if (UTF8::is_ascii($str) && UTF8::is_ascii($search) ) return strpos($str, $search, $offset);
if ( $offset == 0 )
{
$array = explode($search, $str, 2);
return isset($array[1]) ? UTF8::strlen($array[0]) : FALSE;
}
$str = UTF8::substr($str, $offset);
$pos = UTF8::strpos($str, $search);
return ($pos === FALSE) ? FALSE : $pos + $offset;
}