zl程序教程

您现在的位置是:首页 >  前端

当前栏目

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

HTML 标签 文章 运用 截取 过滤 smarty truncate
2023-06-13 09:14:25 时间
strip_tags()函数剥去HTML、XML以及PHP的标签。
复制代码代码如下:

<?phpechostrip_tags(“Hello<b>world!</b>”);?>

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

例如:

index.php:
复制代码代码如下:

$smarty=newSmarty;
$smarty->assign(‘articleTitle",“BlindWomanGets<spanstyle=”font-family:&amp;amp;”>NewKidney</span>fromDadsheHasn"tSeenin<strong>years</strong>.”);
$smarty->display(‘index.tpl");

index.tpl:
复制代码代码如下:
{$articleTitle}
{$articleTitle|strip_tags}

输出结果:
复制代码代码如下:
BlindWomanGets<spanstyle=”font-family:helvetica;”>NewKidney</span>fromDadsheHasn"tSeenin<strong>years</strong>.
BlindWomanGetsNewKidneyfromDadsheHasn"tSeeninyears.

文章截取:
复制代码代码如下:
{$article.content|truncate:35:”…”:true}