smarty中先strip_tags過濾html標簽后truncate截取文章運用
更新時間:2010年10月25日 12:00:29 作者:
strip_tags() 函數剝去 HTML、XML 以及 PHP 的標簽。
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;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}
復制代碼 代碼如下:
<?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;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}