当前位置: 移动技术网 > IT编程>开发语言>PHP > smarty中先strip_tags过滤html标签后truncate截取文章运用

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

2019年04月27日  | 移动技术网IT编程  | 我要评论
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}

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网