如果URL包含Smarty

时间:2011-11-26 19:27:47

标签: php smarty x-cart

使用Smarty标签我想确定一个URL是否包含一个单词,如:

{if $smarty.get.page contains "product.php"} .....

我知道包含不存在,但我怎么能轻易地写一些类似的东西来实现上面的代码呢?

2 个答案:

答案 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变量。