>  기사  >  백엔드 개발  >  Smarty中的注释和截断功能介绍_PHP

Smarty中的注释和截断功能介绍_PHP

WBOY
WBOY원래의
2016-05-29 11:52:19967검색

注释

代码如下:


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


{* 这是一个多行
   Smarty注释
   并不发送到浏览器
*}

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

http://www.itlearner.com/code/smarty_cn/language.basic.syntax.html

截断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 Re..ckout Counter.


可以不用在PHP里截取了:http://www.itlearner.com/code/smarty_cn/language.modifier.truncate.html
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.