当前位置:才华咖 > 互联网计算机 > 计算机 > php语言 > PHP框架之Smarty中的注释和截断功能介绍
手机版

PHP框架之Smarty中的注释和截断功能介绍

来源:才华咖 阅读:1.71W 次

这篇文章主要介绍了Smarty中的`注释和截断功能介绍,这两个功能都是Smarty中不太常用的功能,但非常实用,需要的朋友可以参考下。更多消息请关注应届毕业生网。

PHP框架之Smarty中的注释和截断功能介绍

  注释

代码如下:

{* 这是一个单行Smarty注释 来自于,网页源代码里看不见*}

{* 这是一个多行

Smarty注释

并不发送到浏览器

*}

模板注释由星号包围,继而由分隔符包围,型如:{* 这是一个注释 *}。Smarty注释不会在最终模板的输出中显示,这点和不同。前者对于在模板中插入内部注释有用,因为没有人能看到。;-)

  截断truncate

代码如下:

$smarty->assign('hxtitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter.');

模板为:

代码如下:

{$hxtitle}

{$hxtitle|truncate}

{$hxtitle|truncate:30}

{$hxtitle|truncate:30:""}

{$hxtitle|truncate:30:"---"}

{$hxtitle|truncate:30:"":true}

{$hxtitle|truncate:30:"...":true}

{$hxtitle|truncate:30:'..':true:true}

输出为:

代码如下:

Two Sisters Reunite after Eighteen Years at Checkout Counter.

Two Sisters Reunite after Eighteen Years at Checkout Counter.

Two Sisters Reunite after...

Two Sisters Reunite after

Two Sisters Reunite after---

Two Sisters Reunite after Eigh

Two Sisters Reunite after E...

Two Sisters t Counter.

本文链接:https://www.caihuaka.com/jsjzs/php/g2mx38.html

Copyright © 2024. 才华咖 All right reserved. 浙ICP备20120231号-3

文字美图素材,版权属于原作者。部分文章内容由网友提供推送时因种种原因未能与原作者联系上,若涉及版权问题,敬请原作者联系我们,立即处理。