I'm matching a set of strings against a string and if one of the strings of the array appears in the string, then some text should show up.
In practice: I would like to include a menu only on specific pages. So I include a PHP snippet in my template and the menu should show up when one of the defined page names appears in the URL. Currently I use this code which works:
$domain = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].$_SERVER['QUERY_STRING'];
if (strpos($domain, '/page1.php') !== false) {
echo 'Text',
}
elseif (strpos($domain, '/page2.php') !== false) {
echo 'Text',
}
elseif (strpos($domain, '/page3.php') !== false) {
echo 'Text',
}
elseif (strpos($domain, '/page4.php') !== false) {
echo 'Text',
};
Is it possible to condense the code to make it more efficient rather than repeating for each page an elseif line. I tried the following but it didn't work:
$domain = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].$_SERVER['QUERY_STRING'];
$string = array('page1.php', 'page2.php', 'page3.php', 'page4.php');
if (strpos($domain, $string) !== false) {
echo 'Text',
};
Any suggestions?
Philip