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

前端之家收集整理的这篇文章主要介绍了smarty中先strip_tags过滤html标签后truncate截取文章运用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

strip_tags() 函数剥去 HTML、XML 以及 PHP标签
<div class="codetitle"><a style="CURSOR: pointer" data="5036" class="copybut" id="copybut5036" onclick="doCopy('code5036')"> 代码如下:

<div class="codebody" id="code5036">
<?PHP echo strip_tags(“Hello world!”); ?>

smarty中可以使用strip_tags去除html标签,包括在< >之间的任何内容。 例如: index.PHP:
<div class="codetitle"><a style="CURSOR: pointer" data="96750" class="copybut" id="copybut96750" onclick="doCopy('code96750')"> 代码如下:
<div class="codebody" id="code96750">
$smarty = new Smarty;
$smarty->assign(‘articleTitle',“Blind Woman Gets <span style=”font-family: &amp;amp;”>New Kidney from Dad she Hasn't Seen in

years

.”);
$smarty->display(‘index.tpl');

index.tpl:
<div class="codetitle"><a style="CURSOR: pointer" data="74724" class="copybut" id="copybut74724" onclick="doCopy('code74724')"> 代码如下:
<div class="codebody" id="code74724">
{$articleTitle}
{$articleTitle|strip_tags}

输出结果:
<div class="codetitle"><a style="CURSOR: pointer" data="14245" class="copybut" id="copybut14245" onclick="doCopy('code14245')"> 代码如下:
<div class="codebody" id="code14245">
Blind Woman Gets <span style=”font-family: helvetica;”>New Kidney from Dad she Hasn't Seen in

years

.
Blind Woman Gets New Kidney from Dad she Hasn't Seen in years.

文章截取
<div class="codetitle"><a style="CURSOR: pointer" data="95682" class="copybut" id="copybut95682" onclick="doCopy('code95682')"> 代码如下:<div class="codebody" id="code95682">
{$article.content|truncate:35:”…”:true}

原文链接:https://www.f2er.com/php/28293.html
strip_tagstruncate截取截取

猜你在找的PHP相关文章