Smarty模板处理字符串问题。 请教各位一个小问题,谢谢了。 在smarty模板中有一个字符串,例如ABC/DEF 我想取最后的DEF 应该怎么做呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 {$b.currency_pair|regex_replace:"/^.*\//":""} 每一次遇到问题,都有解决的方法。当你解决了问题时,会发现原来自己一直在进步````学php不久,却喜欢上了这种语言。太完美了。今天遇到了一个乱码问题,这类问题对于一个smarty模板忠实者来说,应该算是普遍性的。个人认为smarty和php是个近乎完美的组合。下面就是解决问题的方法:smarty模板截取字符串后边几个字乱码。改写文件modifier_truncate.phpfunction smarty_modifier_truncatey( $string,$length = 80,$etc='...',$count_words = true ) { mb_internal_encoding("UTF-8"); if ($length == 0)return ''; if ( strlen( $string ) <= $length ) return $string; preg_match_all("/[\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]/", $string, $info); if( $count_words ){ $j = 0; for($i=0; $i<count($info[0]); $i++) { $wordscut .= $info[0][$i]; if( ord( $info[0][$i] ) >=128 ){ $j = $j+2; }else{ $j = $j + 1; } if ($j >= $length ) { return $wordscut.$etc; } } return join('', $info[0]); } return join("",array_slice( $info[0],0,$length ) ).$etc;} 读取{$xnews[t].title|truncate:14}就这么简单```-----------------------------------http://www.jiemengwu.com/ 解梦屋 http://www.phpzy.com/php/ 绿色php资源 问一个数组处理的简单问题 用php做职工档案管理系统方便不? oracle连接php的问题 jpgraph中报错" 图像因其本身有错无法显示" 關於鼠標移動行變顏色問題,還有字體。 !高分急问:怎样怎么从事务日志恢复MYsql数据库 如何对两个二维数组进行比较?不用循环! 一个删除按钮,如何用Javascript做一个弹出窗口,提示确认删除,点确认后才能删除呢? mysql中select语句如果选择的条件否则选出的句柄还会有么? apache2.0.39 php4.2.3在windowsXP下模块方式搭建. php下载文件为空是怎么回事 怎么把PHP页面生成html页??
mb_internal_encoding("UTF-8");
if ($length == 0)return '';
if ( strlen( $string ) <= $length ) return $string;
preg_match_all("/[\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]/", $string, $info);
if( $count_words ){
$j = 0;
for($i=0; $i<count($info[0]); $i++) {
$wordscut .= $info[0][$i];
if( ord( $info[0][$i] ) >=128 ){
$j = $j+2;
}else{
$j = $j + 1;
}
if ($j >= $length ) {
return $wordscut.$etc;
}
}
return join('', $info[0]);
}
return join("",array_slice( $info[0],0,$length ) ).$etc;
} 读取{$xnews[t].title|truncate:14}就这么简单```-----------------------------------
http://www.jiemengwu.com/ 解梦屋 http://www.phpzy.com/php/ 绿色php资源