smarty中先strip_tags過濾html標(biāo)簽后truncate截取文章運(yùn)用
更新時間: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-fpm.conf配置文件中文說明詳解及重要參數(shù)說明
本文主要介紹了php-fpm.conf配置文件的中文說明詳解以及php-fpm.conf重要參數(shù)配置說明,最后有一個監(jiān)控php-fpm進(jìn)程運(yùn)行狀態(tài)的頁面代碼實例2018-10-10
PHP基于反射機(jī)制實現(xiàn)自動依賴注入的方法詳解
這篇文章主要介紹了PHP基于反射機(jī)制實現(xiàn)自動依賴注入的方法,結(jié)合實例形式分析了php使用反射實現(xiàn)自動依賴注入的步驟、原理與相關(guān)操作技巧,需要的朋友可以參考下2017-12-12
php網(wǎng)頁標(biāo)題中文亂碼的有效解決方法
測試了php的網(wǎng)頁發(fā)現(xiàn)標(biāo)題中文亂碼,在網(wǎng)上搜索了下面的解決方法,需要的朋友可以參考下2014-03-03
php下關(guān)于中英數(shù)字混排的字符串分割問題
要用到短信平臺的緣故,短信每條又有字?jǐn)?shù)的限制,而短信平臺的服務(wù)端又不會自己分析。短信平臺的后臺會自己分割,但api卻有沒這個功能。2010-04-04
PHP將二維數(shù)組某一個字段相同的數(shù)組合并起來的方法
這篇文章主要介紹了PHP將二維數(shù)組某一個字段相同的數(shù)組合并起來的方法,涉及PHP多維數(shù)組操作的相關(guān)技巧,需要的朋友可以參考下2016-02-02

