发布于 2014-11-03 00:56:04 | 865 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

Smarty模板引擎

Smarty是一个使用PHP写出来的模板引擎,是目前业界最著名的PHP模板引擎之一。它分离了逻辑代码和外在的内容,提供了一种易于管理和使用的方法,用来将原本与HTML代码混杂在一起PHP代码逻辑分离。简单的讲,目的就是要使PHP程序员同前端人员分离,使程序员改变程序的逻辑内容不会影响到前端人员的页面设计,前端人员重新修改页面不会影响到程序的程序逻辑,这在多人合作的项目中显的尤为重要。


本文为大家讲解的是示例是smarty中先strip_tags过滤html标签后truncate截取文章使用说明,感兴趣的同学参考下。


strip_tags() 函数剥去 HTML、XML 以及 PHP 的标签。


<?php echo strip_tags(“Hello <b>world!</b>”); ?>


smarty中可以使用strip_tags去除html标签,包括在< >之间的任何内容。

例如:

index.php:


$smarty = new Smarty;
$smarty->assign(‘articleTitle', “Blind Woman Gets <span style=”font-family: &amp;amp;”>New Kidney</span> from Dad she Hasn't Seen in <strong>years</strong>.”);
$smarty->display(‘index.tpl');


index.tpl:


{$articleTitle}
{$articleTitle|strip_tags}


输出结果:


Blind Woman Gets <span style=”font-family: helvetica;”>New Kidney</span> from Dad she Hasn't Seen in <strong>years</strong>.
Blind Woman Gets New Kidney from Dad she Hasn't Seen in years.


文章截取:


{$article.content|truncate:35:”…”:true}

 



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务