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;”>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}
如对本文有疑问,
点击进行留言回复!!
网友评论