php Smarty 如果 URL 包含

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8280984/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 04:20:38  来源:igfitidea点击:

Smarty If URL Contains

phpsmartyx-cart

提问by 99823

Using Smarty Tags I'd like to determine if an URL contains a word, something like:

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

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

I know contains doesn't exist, but how could I easily go about writing something similar to achieve the above code?

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

采纳答案by tekknolagi

You can use strposto check if a string has another string inside of it.

你可以strpos用来检查一个字符串里面是否有另一个字符串。

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

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

Except you need to wrap it in {php}and {/php}.

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

$smarty.get.pagetranslates to $_GET['page'], so you could replace it with the GET variable as well.

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

回答by meze

All PHP conditionals and functions are recognized, such as ||, or, &&, and, is_array(), etc.

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

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

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