程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> smarty中先strip_tags過濾html標簽後truncate截取文章運用

smarty中先strip_tags過濾html標簽後truncate截取文章運用

編輯:關於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}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved