09
Mar

自动识别汉字的PHP截取字符串函数


版权声明:可以在网上任意转载,转载时请务必以超链接形式标明文章原始出处、作者信息及本声明文字。
作者:shunz,出处:http://shunz.net/2004/03/9.html

function LeftTrue($str,$n,$str2,$m,$type)
{

$l=strlen($str);
$TStr="";
$t=0;
for ($i=0; $i<$l; $i++)
{
$c=ord(substr($str,$i,1));
if ($c<0)
$c=$c+65536;
if
($c>127) {
$t+=2;
$TStr=$TStr.(substr($str,$i,2));
$i++;
}else
{
$t++;
$TStr=$TStr.(substr($str,$i,1));
}
if
($t>=$n)
break;
}
if($t>=$n || !$type)
{
$function_ret=$TStr.str_repeat($str2,$n+$m-$t);
}else
{
$function_ret=$TStr;
for($i=$t;$i<$n+$m;$i++)
$function_ret.=" ";
}
return
$function_ret;
}

没有评论

第一个在本文留言。

发表评论

名字(必须)
邮箱(不会被公布)(必须)
网址

字体为 粗体 是必填项目,邮箱地址 永远不会 公布。

允许部分 HTML 代码:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
URIs must be fully qualified (eg: http://shunz.net/) and all tags must be properly closed.

超出部分系统将会自动分段及换行。

请保证评论内容是与日志或 Blog 内容相关的,灌水、攻击性或不恰当的评论 may 会被编辑或删除。

    关于

      我,shunz,在这里默默记录自己的所学所思以及所关注的事情...
      Blog del.icio.us Flickr Furl Gmail/Google Talk Google Reader Google Shared Stuff Picasa Web Albums Twitter YouTube Zooomr douban

    订阅

    页面

    广告

    分类