基于URL的php if elseif通配符
到处寻找更简单的方法来做我所做的 我有一个函数,它生成基于URL的php if elseif通配符,php,url,if-statement,canonical-link,Php,Url,If Statement,Canonical Link,到处寻找更简单的方法来做我所做的 我有一个函数,它生成$absLink结果,即'www.example.com/current/page/' 然后,我将其用于php if和elseif,以执行以下操作: <?php else if ($absLink == 'www.example.com/homepage/' { ?> This the homepage <?php } elseif ($absLink == 'www.example.com/about/' { ?>
$absLink
结果,即'www.example.com/current/page/'
然后,我将其用于php if和elseif,以执行以下操作:
<?php else if ($absLink == 'www.example.com/homepage/' { ?>
This the homepage
<?php } elseif ($absLink == 'www.example.com/about/' { ?>
This the about page
<?php } else { ?>
This probably the 404 not found page
<?php } ?>
有道理吗?p、 s.
$absLink
代表绝对链接,尽管我最近从中删除了http://
,因为这只是我决定的一个无用的麻烦。您可以使用strpos
查看变量是否包含url
if (strpos($absLink,'www.ohiowebgroup.com/about/')>=0)
所以在这里,如果$absLink包含www.ohiowebgroup.com/about/,则它将返回其位置,如果在开头找到该位置,该位置将为零,或者根据找到位置返回一个正数。现在,无论
关于/
之后发生了什么,这个条件都是真的,因此它对您的问题很有效
希望这有帮助。尝试使用strps函数,检查stringWow中是否存在子字符串,是的,这很有效!非常感谢。明亮的我在打你的箭啊,妈的,现在它制造了各种各样的问题。我正试图弄清事情的真相,以便能给你一个好的解释
if (strpos($absLink,'www.ohiowebgroup.com/about/')>=0)