11

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

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

我知道 contains 不存在,但我怎么能轻松地编写类似的东西来实现上述代码?

4

2 回答 2

28

识别所有 PHP 条件和函数,例如 ||、or、&&、and、is_array() 等。

{if strpos($smarty.get.page, "product.php") !== false}

于 2011-11-26T19:47:19.333 回答
9

您可以使用它strpos来检查一个字符串中是否有另一个字符串。

$pos = strpos($smarty.get.page, "product.php");

if($pos !== false) {
 // found, do something
}

除非您需要将其包装在{php}and中{/php}

$smarty.get.page转换为$_GET['page'],因此您也可以将其替换为 GET 变量。

于 2011-11-26T19:31:21.370 回答