使用Smarty标签我想确定一个URL是否包含一个单词,如:
{if $smarty.get.page contains "product.php"} .....
我知道包含不存在,但我怎么能轻易地写一些类似的东西来实现上面的代码呢?
答案 0 :(得分:25)
识别所有PHP条件和函数,例如||,或&&,and,is_array()等。
{if strpos($smarty.get.page, "product.php") !== false}
答案 1 :(得分:5)
您可以使用strpos
检查字符串中是否包含其他字符串。
$pos = strpos($smarty.get.page, "product.php");
if($pos !== false) {
// found, do something
}
除非您需要将其包含在{php}
和{/php}
。
$smarty.get.page
会转换为$_GET['page']
,因此您也可以将其替换为GET变量。