主题:字符截取函数··
elancn8603
[专家分:30] 发布于 2010-06-14 22:50:00
在这个代码中
<a href="/team.php?id={$one['id']}" title="{$one['title']}" target="_blank">{$one['title']}</a>
{$one['title']}取得的标题太长了,我想用mb_substr 来控制下字数,但苦于是初学者,不知道怎么加,希望有人能指点指点,我先谢谢了啊·
回复列表 (共2个回复)
沙发
two0426 [专家分:0] 发布于 2010-07-17 10:05:00
[img]http://res.wowshell.com/upload/img/19/090330/2240482584630.jpg[/img]
Needless to say, the LemonQTs are not the only ones who have proven they can play RMP with a good win dsjkvbvoo klfjsdjkfl$%$ ratio wow gold [url=http://www.gamegoldvip.org/]wow gold[/url] about power leveling, as with the new pickup, GG has already began to demonstrate their skill with the comp. [url=http://www.gamegoldvip.org/gold.aspx/]wow gold[/url] Everyone is being tight lipped about this but if the speculation coming from some of the power players of [url=http://www.trendress.com/]Wedding Dresses[/url] ESL. This is a new story and as more details come I will update this post to get power leveling. I am also wow gold [url=http://www.trendress.com/wedding-dresses-C23/]Wedding Dresses[/url] compiling a quick history of ESL in respect to power levelingbut for people who want to know more about it [url=http://www.trendress.com/discount-wedding-dresses-C46/]Discount Wedding Dresses[/url] check it hereI also have an audio interview with the infamous EU Warrior Ocelote that I will be appending to [url=http://www.trendress.com/mother-of-groom-dresses-C48/]Mother of Groom Dresses[/url] this post later tonight so be sure to check back kgdfjk$%^%$jhgfd if you are interested. You can practically taste the salty, venomous spittle of RTS 0717lj.
★★☆Related Article☆★★
[url=http://feilang.blogownia.pl/54374/General+thoughts+on+healing+wow+power+leveling+.html]http://feilang.blogownia.pl/54374/General+thoughts+on+healing+wow+power+leveling+.html[/url]
[url=http://xiaoge.journalspace.com/2010/07/16/addon-spotlight-focuses-on-wow-gold-addon-spotlight-focuses-on-wow-gold/]http://xiaoge.journalspace.com/2010/07/16/addon-spotlight-focuses-on-wow-gold-addon-spotlight-focuses-on-wow-gold/[/url]
[url=http://blog.gojini.com/feilang/11499/General+thoughts+on+healing+wow+power+leveling+.html]http://blog.gojini.com/feilang/11499/General+thoughts+on+healing+wow+power+leveling+.html[/url]
[url=http://feilang.tradea.org/21938/General+thoughts+on+healing+wow+power+leveling+.html]http://feilang.tradea.org/21938/General+thoughts+on+healing+wow+power+leveling+.html[/url]
[url=http://www.myclassicalgas.com/view.blog.php?id=475]http://www.myclassicalgas.com/view.blog.php?id=475[/url]
[url=http://www.absolutepunk.net/journal.php?do=showcomments&j=37562&e=296812]http://www.absolutepunk.net/journal.php?do=showcomments&j=37562&e=296812[/url]
板凳
S71ENCE [专家分:0] 发布于 2010-09-23 21:27:00
看代码你应该是使用了模板,我以smarty 模板为例:
首先是两个字符串截取的函数 1为带有"..." 2没有
/*
字符串截取
*/
function mysubstr($string, $sublen, $start) {
$pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/";
preg_match_all($pa, $string, $t_string);
if(count($t_string[0]) - $start > $sublen) return join('', array_slice($t_string[0], $start, $sublen))."...";
return join('', array_slice($t_string[0], $start, $sublen));
}
/*
字符串截取 不加"..."
*/
function mysubstr_00($string, $sublen, $start) {
$pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/";
preg_match_all($pa, $string, $t_string);
return join('', array_slice($t_string[0], $start, $sublen));
}
$title_old="这是一个很长很长的需要截取的标题";
$title_new=mysubstr_00($title_old,10,0)//被截取的字符串,截取字符数,起始位置
$smarty->assign("title",$titel_new);
前台:
{$title}
我来回复