聪明,如果URL包含 [英] Smarty If URL Contains

查看:87
本文介绍了聪明,如果URL包含的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

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

推荐答案

您可以使用strpos检查一个字符串中是否包含另一个字符串.

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

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

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

除了需要将其包装在{php}{/php}中.

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

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

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

这篇关于聪明,如果URL包含的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆