/** |
* 中英文截取 |
* @param string 要截取的字符串 |
* @param string 要截取的长度(超过总长度 按总长度计算) |
* @param [string] (可选)开始位置(第一个为0) |
* @return string |
* @author 小墨 244349067@qq.com |
*/ |
function mixSubstr( $str , $length , $start =FALSE) |
{ |
if ( ! $length ){ |
return false; |
} |
|
$strlen = strlen ( $str ); |
$content = '' ; |
$sing = 0; |
$count = 0; |
|
if ( $length > $strlen ) { |
$length = $strlen ; |
} |
if ( $start >= $strlen ) { |
return false; |
} |
|
while ( $length != ( $count - $start )) |
{ |
if (ord( $str [ $sing ]) > 0xa0) { |
if (! $start || $start <= $count ) { |
$content .= $str [ $sing ]. $str [ $sing +1]. $str [ $sing +2]; |
} |
$sing += 3; |
$count ++; |
} else { |
if (! $start || $start <= $count ) { |
$content .= $str [ $sing ]; |
} |
$sing ++; |
$count ++; |
} |
} |
return $content ; |
} |