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

yipeiwu_com6年前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获取指定范围内最接近数的方法

本文实例讲述了php获取指定范围内最接近数的方法。分享给大家供大家参考。具体实现方法如下: // Returns the next higher or lower number fu...

php+js iframe实现上传头像界面无跳转

上传头像,界面无跳转的方式很多,我用的是加个iframe那种。下面直接上代码。 html: 复制代码 代码如下: //route 为后端接口 //upload/avatar 为上传的头像...

解析PHP汉字转换拼音的类

网络上类似的代码大多只能在gb2312编码下使用,下面这个类同时能在utf-8编码下将汉字转换为拼音。具体的代码和用法如下:复制代码 代码如下:<?phpfunction Piny...

真正根据utf8编码的规律来进行截取字符串的函数(utf8版sub_str )

复制代码 代码如下: /* * 功能: 作用跟substr一样,除了它不会造成乱码 * 参数: * 返回: */ function utf8_substr( $str , $start...

php简单对象与数组的转换函数代码(php多层数组和对象的转换)

复制代码 代码如下: function arrayToObject($e){ if( gettype($e)!='array' ) return; foreach($e as $k=&g...