php Smarty 字符比較代碼
更新時(shí)間:2011年02月27日 15:14:29 作者:
php Smarty 字符比較代碼,需要的朋友可以參考下。
eq相等,
ne、neq不相等,
gt大于,
lt小于,
gte、ge大于等于,
lte、le 小于等于,
not非, mod求模。
is [not] div by是否能被某數(shù)整除,
is [not] even是否為偶數(shù),
$a is [not] even by $b即($a / $b) % 2 == 0,
is [not] odd是否為奇,
$a is not odd by $b即($a / $b) % 2 != 0 示例:
equal/ not equal/ greater than/ less than/ less than or equal/ great than or equal/后面的就不用說了
Smarty 中的 if 語句和 php 中的 if 語句一樣靈活易用,并增加了幾個(gè)特性以適宜模板引擎. if 必須于 /if 成對出現(xiàn). 可以使用 else 和 elseif 子句. 可以使用以下條件修飾詞:eq、ne、neq、gt、lt、lte、le、gte、ge、is even、is odd、is not even、is not odd、not、mod、div by、even by、odd by、==、!=、>、<、<=、>=. 使用這些修飾詞時(shí)必須和變量或常量用空格格開.
Example 7-11. if statements
例 7-11. if 語句演示
{if $name eq "Fred"}
Welcome Sir.
{elseif $name eq "Wilma"}
Welcome Ma'am.
{else}
Welcome, whatever you are.
{/if}
{* an example with "or" logic *}
{if $name eq "Fred" or $name eq "Wilma"}
...
{/if}
{* same as above *}
{if $name == "Fred" || $name == "Wilma"}
...
{/if}
{* the following syntax will NOT work, conditional qualifiers
must be separated from surrounding elements by spaces *}
{if $name=="Fred" || $name=="Wilma"}
...
{/if}
{* parenthesis are allowed *}
{if ( $amount < 0 or $amount > 1000 ) and $volume >= #minVolAmt#}
...
{/if}
{* you can also embed php function calls *}
{if count($var) gt 0}
...
{/if}
{* test if values are even or odd *}
{if $var is even}
...
{/if}
{if $var is odd}
...
{/if}
{if $var is not odd}
...
{/if}
{* test if var is divisible by 4 *}
{if $var is div by 4}
...
{/if}
{* test if var is even, grouped by two. i.e.,
0=even, 1=even, 2=odd, 3=odd, 4=even, 5=even, etc. *}
{if $var is even by 2}
...
{/if}
{* 0=even, 1=even, 2=even, 3=odd, 4=odd, 5=odd, etc. *}
{if $var is even by 3}
...
{/if}
ne、neq不相等,
gt大于,
lt小于,
gte、ge大于等于,
lte、le 小于等于,
not非, mod求模。
is [not] div by是否能被某數(shù)整除,
is [not] even是否為偶數(shù),
$a is [not] even by $b即($a / $b) % 2 == 0,
is [not] odd是否為奇,
$a is not odd by $b即($a / $b) % 2 != 0 示例:
equal/ not equal/ greater than/ less than/ less than or equal/ great than or equal/后面的就不用說了
Smarty 中的 if 語句和 php 中的 if 語句一樣靈活易用,并增加了幾個(gè)特性以適宜模板引擎. if 必須于 /if 成對出現(xiàn). 可以使用 else 和 elseif 子句. 可以使用以下條件修飾詞:eq、ne、neq、gt、lt、lte、le、gte、ge、is even、is odd、is not even、is not odd、not、mod、div by、even by、odd by、==、!=、>、<、<=、>=. 使用這些修飾詞時(shí)必須和變量或常量用空格格開.
Example 7-11. if statements
例 7-11. if 語句演示
{if $name eq "Fred"}
Welcome Sir.
{elseif $name eq "Wilma"}
Welcome Ma'am.
{else}
Welcome, whatever you are.
{/if}
{* an example with "or" logic *}
{if $name eq "Fred" or $name eq "Wilma"}
...
{/if}
{* same as above *}
{if $name == "Fred" || $name == "Wilma"}
...
{/if}
{* the following syntax will NOT work, conditional qualifiers
must be separated from surrounding elements by spaces *}
{if $name=="Fred" || $name=="Wilma"}
...
{/if}
{* parenthesis are allowed *}
{if ( $amount < 0 or $amount > 1000 ) and $volume >= #minVolAmt#}
...
{/if}
{* you can also embed php function calls *}
{if count($var) gt 0}
...
{/if}
{* test if values are even or odd *}
{if $var is even}
...
{/if}
{if $var is odd}
...
{/if}
{if $var is not odd}
...
{/if}
{* test if var is divisible by 4 *}
{if $var is div by 4}
...
{/if}
{* test if var is even, grouped by two. i.e.,
0=even, 1=even, 2=odd, 3=odd, 4=even, 5=even, etc. *}
{if $var is even by 2}
...
{/if}
{* 0=even, 1=even, 2=even, 3=odd, 4=odd, 5=odd, etc. *}
{if $var is even by 3}
...
{/if}
您可能感興趣的文章:
- 探討Smarty中如何獲取數(shù)組的長度以及smarty調(diào)用php函數(shù)的詳解
- PHP 基于Yii框架中使用smarty模板的方法詳解
- 基于PHP Web開發(fā)MVC框架的Smarty使用說明
- 在smarty中調(diào)用php內(nèi)置函數(shù)的方法
- FCKeditor smarty 編輯器的應(yīng)用PHP
- smarty實(shí)現(xiàn)PHP靜態(tài)化的兩種方法分享
- php使用Smarty的相關(guān)注意事項(xiàng)及訪問變量的幾種方式
- php smarty截取中文字符亂碼問題?gb2312/utf-8
- php Smarty初體驗(yàn)二 獲取配置信息
- php中Smarty模板初體驗(yàn)
- php smarty 二級分類代碼和模版循環(huán)例子
- php smarty 二級分類代碼和模版循環(huán)例子
- 在smarty模板中使用PHP函數(shù)的方法
- php Smarty模板生成html文檔的方法
- php smarty函數(shù)擴(kuò)展
- php Smarty date_format [格式化時(shí)間日期]
- php smarty模版引擎中變量操作符及使用方法
- 關(guān)于PHP模板Smarty的初級使用方法以及心得分享
相關(guān)文章
jQuery+php實(shí)現(xiàn)ajax文件即時(shí)上傳的詳解
本篇文章是對jQuery+php實(shí)現(xiàn)ajax文件即時(shí)上傳的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
php實(shí)現(xiàn)插入數(shù)組但不影響原有順序的方法
這篇文章主要介紹了php實(shí)現(xiàn)插入數(shù)組但不影響原有順序的方法,實(shí)例分析了php數(shù)組操作的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-03-03
PHP+原生態(tài)ajax實(shí)現(xiàn)的省市聯(lián)動(dòng)功能詳解
這篇文章主要介紹了PHP+原生態(tài)ajax實(shí)現(xiàn)的省市聯(lián)動(dòng)功能,較為詳細(xì)的分析了ajax交互的原理、實(shí)現(xiàn)方法以及php結(jié)合ajax實(shí)現(xiàn)省市聯(lián)動(dòng)下拉菜單功能的相關(guān)操作技巧,需要的朋友可以參考下2017-08-08
phpinfo() 中 Local Value(局部變量)Master Value(主變量) 的區(qū)別
這篇文章主要介紹了phpinfo() 中 Local Value(局部變量)Master Value(主變量) 的區(qū)別,需要的朋友可以參考下2016-02-02
PHP類相關(guān)知識點(diǎn)實(shí)例總結(jié)
這篇文章主要介紹了PHP類相關(guān)知識點(diǎn),結(jié)合實(shí)例形式總結(jié)分析了php類相關(guān)的最終類、最終方法、抽象類、抽象方法、接口、重載、魔術(shù)方法等相關(guān)概念與操作技巧,需要的朋友可以參考下2016-09-09
PHP中函數(shù)gzuncompress無法使用的解決方法
這篇文章主要介紹了PHP中函數(shù)gzuncompress無法使用的解決方法,文中的介紹的很詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧。2017-03-03

