smarty中先strip_tags过滤html标签后truncate截取文章运用
作者:bea
strip_tags() 函数剥去 HTML、XML 以及 PHP 的标签。 代码如下: <?php echo strip_tags(“Hello <b>world!</b>”); ?> smarty中可以使用strip_tags去除html标签,包括在< >之间的任何内容。 例如: index.php: 代码如下: $smarty = new Smarty; $smarty->assign(‘artic
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;”>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;”>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}
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- 批量修改RAR文件注释的php代码
- 为PHP初学者的8点有效建议
- PHP程序员最常犯的11个MySQL错误小结
- Windows 下的 PHP-PEAR 安装方法
- 整理的9个实用的PHP库简介和下载
- Notice: Undefined index: page in E:PHP est.php on line 14
- php运行出现Call to undefined function curl_init()的解决方法
- 《PHP编程最快明白》第八讲:php启发和小结
- 《PHP编程最快明白》第七讲:php图片验证码与缩略图
- 《PHP编程最快明白》第六讲:Mysql数据库操作
- 《PHP编程最快明白》第五讲:php目录、文件操作
- 《PHP编程最快明白》第四讲:日期、表单接收、session、cookie
- 《PHP编程最快明白》第三讲:php数组
- 《PHP编程最快明白》第二讲 数字、浮点、布尔型、字符串和数组
- 一篇有意思的技术文章php介绍篇
- 理解php原理的opcodes(操作码)
- PHP下常用正则表达式整理
- PHP编程最快明白(第一讲 软件环境和准备工作)
- 微盾PHP脚本加密专家php解密算法