smarty中先strip_tags過濾html標(biāo)簽后truncate截取文章運(yùn)用
更新時(shí)間:2010年10月25日 12:00:29 作者:
strip_tags() 函數(shù)剝?nèi)?HTML、XML 以及 PHP 的標(biāo)簽。
strip_tags() 函數(shù)剝?nèi)?HTML、XML 以及 PHP 的標(biāo)簽。
<?php echo strip_tags(“Hello <b>world!</b>”); ?>
smarty中可以使用strip_tags去除html標(biāo)簽,包括在< >之間的任何內(nèi)容。
例如:
index.php:
$smarty = new Smarty;
$smarty->assign(‘a(chǎn)rticleTitle', “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}
輸出結(jié)果:
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}
復(fù)制代碼 代碼如下:
<?php echo strip_tags(“Hello <b>world!</b>”); ?>
smarty中可以使用strip_tags去除html標(biāo)簽,包括在< >之間的任何內(nèi)容。
例如:
index.php:
復(fù)制代碼 代碼如下:
$smarty = new Smarty;
$smarty->assign(‘a(chǎn)rticleTitle', “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:
復(fù)制代碼 代碼如下:
{$articleTitle}
{$articleTitle|strip_tags}
輸出結(jié)果:
復(fù)制代碼 代碼如下:
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.
文章截?。?
復(fù)制代碼 代碼如下:
{$article.content|truncate:35:”…”:true}
相關(guān)文章
PHP使用兩個(gè)棧實(shí)現(xiàn)隊(duì)列功能的方法
這篇文章主要介紹了PHP使用兩個(gè)棧實(shí)現(xiàn)隊(duì)列功能的方法,結(jié)合實(shí)例形式分析了php基于兩個(gè)棧實(shí)現(xiàn)隊(duì)列功能的思路與具體操作技巧,需要的朋友可以參考下2018-01-01
PHP實(shí)現(xiàn)的字符串匹配算法示例【sunday算法】
這篇文章主要介紹了PHP實(shí)現(xiàn)的字符串匹配算法,簡(jiǎn)單描述了sunday算法的概念與原理,并結(jié)合實(shí)例形式分析了php基于sunday算法實(shí)現(xiàn)字符串匹配操作相關(guān)技巧,需要的朋友可以參考下2017-12-12
生成靜態(tài)頁面的php函數(shù),php愛好者站推薦
生成靜態(tài)頁面的php函數(shù),php愛好者站推薦...2007-03-03
mac系統(tǒng)下安裝多個(gè)php并自由切換的方法詳解
本文主要介紹了在mac系統(tǒng)下安裝多個(gè)php并自由切換的方法,文中先介紹了安裝多版本php的方法以及遇到相關(guān)錯(cuò)誤的解決方法,版本切換主要是利用php-version工具,php-version是一個(gè)幫助管理從brew安裝的php版本切換的工具,需要的朋友可以參考,下面來一起看看吧。2017-04-04
php簡(jiǎn)單實(shí)現(xiàn)發(fā)送帶附件的郵件
這篇文章主要介紹了php簡(jiǎn)單實(shí)現(xiàn)發(fā)送帶附件的郵件,涉及附件上傳及郵件發(fā)送的相關(guān)技巧,需要的朋友可以參考下2015-06-06

