smarty中先strip_tags过滤html标签后truncate截取文章运用

yipeiwu_com5年前PHP代码库
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}

相关文章

解析php中array_merge与array+array的区别

array_merge是丢弃原来的数字的key,而保留字符串形式的key,然后组成一个新的数组,不管键名是否一样,都不合并,除非键名和value同时一样并且还必须是字符串形式的key才合...

修改了一个很不错的php验证码(支持中文)

php英文验证码captcha.class.php 复制代码 代码如下: <?php class Captcha { private $width; private $height...

浅析php header 跳转

PHP的header函数 可以很少代码就能实现HTML代码中META 标签这里只说用 header函数来做页面的跳转 1. HTML代码中页面的跳转的代码HTML meta refres...

Ajax+PHP 边学边练 之二 实例

Ajax+PHP 边学边练 之二 实例

效果1. 当鼠标放在某日上时,如果当天有备忘录,则会显示出来,如下图: 复制代码 代码如下: function checkfortasks (thedate, e){ //找到页面中ta...

一个简单至极的PHP缓存类代码

网上关于 PHP 缓存类的资料很多,不过这个类应该是我见过功能满足需求,但又无比简洁的一个。废话不多说,直接看代码吧! 使用说明: 1、实例化 $cache = new Cache();...