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