社区
基础编程
帖子详情
Smarty模板处理字符串问题。
thisboy_star
2010-12-17 09:13:52
请教各位一个小问题,谢谢了。
在smarty模板中有一个字符串,例如ABC/DEF 我想取最后的DEF 应该怎么做呢?
...全文
173
4
打赏
收藏
Smarty模板处理字符串问题。
请教各位一个小问题,谢谢了。 在smarty模板中有一个字符串,例如ABC/DEF 我想取最后的DEF 应该怎么做呢?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
4 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
wuyuanyue2
2010-12-17
打赏
举报
回复
每一次遇到问题,都有解决的方法。
当你解决了问题时,会发现原来自己一直在进步````
学php不久,却喜欢上了这种语言。太完美了。
今天遇到了一个乱码问题,这类问题对于一个smarty模板忠实者来说,应该算是普遍性的。
个人认为smarty和php是个近乎完美的组合。
下面就是解决问题的方法:
smarty模板截取字符串后边几个字乱码。
改写文件modifier_truncate.php
function 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资源
ihefe
2010-12-17
打赏
举报
回复
JF
thisboy_star
2010-12-17
打赏
举报
回复
自己弄出来了。
thisboy_star
2010-12-17
打赏
举报
回复
{$b.currency_pair|regex_replace:"/^.*\//":""}
smarty
模板
中拼接
字符串
的方法
主要介绍了
smarty
模板
中拼接
字符串
的方法,需要的朋友可以参考下
smarty
模板
引擎使用内建函数foreach循环取出所有数组值的方法
主要介绍了
smarty
模板
引擎使用内建函数foreach循环取出所有数组值的方法,实例分析了foreach循环遍历数组的几种常用技巧,需要的朋友可以参考下
smarty
3 的应用详解
除此之外,新支持
字符串
类型的
模板
,感觉比较生猛,离
模板
之路也是渐行渐远: 代码片断: $
smarty
->display('string:This is my template, {$foo}!');
smarty
3的相关链接
Smarty
3 Alpha with SVN-- 选择googlecode...
smarty
手册.chm
string_format [
字符串
格式化] strip [去除(多余空格)] strip_tags [去除html标签] truncate [截取] upper [大写] wordwrap [行宽约束] 6. Combining Modifiers [组合修改器] 7. Built-in Functions [内建...
Smarty
中文手册 chm版
string_format [
字符串
格式化] strip [去除(多余空格)] strip_tags [去除html标签] truncate [截取] upper [大写] wordwrap [行宽约束] 6. Combining Modifiers [组合修改器] 7. Built-in Functions [内建...
基础编程
21,887
社区成员
140,363
社区内容
发帖
与我相关
我的任务
基础编程
从PHP安装配置,PHP入门,PHP基础到PHP应用
复制链接
扫一扫
分享
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章