I have used several character-retrieving functions such as mb_substr, but they are not very easy to use. This one is better.
[php]
/**
* Truncate functions to prevent garbled characters
*
*
*/
function z_substr($sourcestr='',$i=0,$cutlength=150,$endstr='')
{
$str_length=strlen($sourcestr);//Number of bytes of string
while (($n<$cutlength) and ($i<=$str_length))
{
$temp_str=substr($sourcestr,$i,1);
$ascnum=Ord($temp_str);//ascii code
If ($ascnum>=224)
$returnstr=$returnstr.substr($sourcestr,$i,3);
$i=$i+3;
}elseif ($ascnum>=192)
$returnstr=$returnstr.substr($sourcestr,$i,2);
$i=$i+2;
}else
$returnstr=$returnstr.substr($sourcestr,$i,1);
$i=$i+1;
$n=$n+0.5;
}
If($i<$str_length)$returnstr.=$endstr;
Return $returnstr;
}
http://www.bkjia.com/PHPjc/477395.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/477395.html
I have used several character-retrieving functions such as mb_substr, but they are not very easy to use. This one is better. [php] /*** Truncate functions to prevent garbled characters * **/ function z_substr($sourcestr=,$i=...