champrock Posted April 9, 2008 Share Posted April 9, 2008 [code=php:0]<?php if ($pageURL === "abc.com" || "xyz.com" || "pqr.com" || "aer.com") { echo 'something'; } ?> [/code] helo. i am looking to create some snippet which basically does the following work 1. the $pageURL string contains this $_SERVER["SERVER_NAME"] (the domain of the page) 2. i want to match it up with few matches and output something in particular if the $pageURL is same as the above four matches. and not echo anything when $pageURL is different from the above 4. but when i am using this code, it is echoing "something" in every domain, even in lets say "blahblah.com" and "tommy.com". the logical comparison is not working any suggestions where i am going wrong? Link to comment https://forums.phpfreaks.com/topic/100258-solved-simple-php-help/ Share on other sites More sharing options...
eRott Posted April 9, 2008 Share Posted April 9, 2008 <?php if ($pageURL == "abc.com") { echo 'something if domain is abc.com'; } elseif ($pageURL == "xyz.com") { echo 'something if domain is xyz.com'; } elseif ($pageURL == "pqr.com") { echo 'something if domain is pqr.com'; } else { echo 'something if domain is none of the above'; } ?> Link to comment https://forums.phpfreaks.com/topic/100258-solved-simple-php-help/#findComment-512637 Share on other sites More sharing options...
trq Posted April 9, 2008 Share Posted April 9, 2008 To do it your way you would need.... <?php if ($pageURL == "abc.com" || $pageURL == "xyz.com" || $pageURL == "pqr.com" || $pageURL == "aer.com") { echo 'something'; } ?> A better solution.... <?php if (in_array($pageURL,array("abc.com","xyz.com","pqr.com","aer.com")) { echo 'Something'; } ?> Link to comment https://forums.phpfreaks.com/topic/100258-solved-simple-php-help/#findComment-512638 Share on other sites More sharing options...
champrock Posted April 9, 2008 Author Share Posted April 9, 2008 thanks a lot for ur prompt reply. <?php if (in_array($pageURL,array("abc.com","xyz.com","pqr.com","aer.com")) { echo 'Something'; } ?> i am using this code, but this still does not work. i dont know why but it is still showing "something" for domains which are not in that array. any way to make it case-insensitive? Link to comment https://forums.phpfreaks.com/topic/100258-solved-simple-php-help/#findComment-512648 Share on other sites More sharing options...
champrock Posted April 9, 2008 Author Share Posted April 9, 2008 thanks it works... used some minor editing and it works absolutely fine Link to comment https://forums.phpfreaks.com/topic/100258-solved-simple-php-help/#findComment-512654 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.