Hello, I've been using this bit of PHP code within my "sidebar.php" file to insert menu items (external links) depending on what URI is viewed, and and it works great so far: <?php $homepage = "/"; $currentpage = $_SERVER['REQUEST_URI']; if($homepage==$currentpage) { include('homepage-only-stuff.php'); } ?> <?php $antivirus = "/anti-virus/"; $antivirussub = "/anti-virus/anti-virus-articles.php"; $currentpage = $_SERVER['REQUEST_URI']; if(($antivirus==$currentpage) || ($antivirussub==$currentpage)) { include('antivirus-only-stuff.php'); } ?> PHP: ETC... (you get the picture ) But now I want to exclude my blog pages. I can if I use: <?php $homepage = "/weblog/"; $currentpage = $_SERVER['REQUEST_URI']; if($homepage!=$currentpage) { include('non-blog-stuff.php'); } ?> PHP: But that does not match all the specific post pages, nor do I want to hard-code every post URI I make anyway So, how can I check for /weblog/AnyPostPage-URI/ (as a "wildcard" kind of match?) and exclude them?
Try this <?php $homepage = "/weblog/"; $currentpage = $_SERVER['REQUEST_URI']; if(strpos($currentpage, $homepage) === FALSE) { include('non-blog-stuff.php'); } ?> PHP:
Tonybogs, You rock! That works perfectly. Finding that needle in the haystack makes perfect sense. Can I ask why the triple "if equal" (===) instead of == ? PS: You get some cool green rep and iTrade for this PSS: I was able to green rep you, but I get an error every time I try the process of iTrading...
The === FALSE means an absolute match. The problem being 0 also == FALSE So if the position of /weblog/ is 0, which it will be as its the first part of the URI the outcome of strpos($currentpage, $homepage) will be 0 and 0 == FALSE so youll be including the file everytime. I hope that is clear. I appreciate the rep, no worries about the iTrade just happy to help out Good Luck with your site