Page 1 of 1

Combine these

Posted: Fri Feb 24, 2012 1:28 pm
by mealto
I got this working in Drupal but could not get these separate calls to be combined. Can anyone help with teh syntax?

$currentpage = $_SERVER['REQUEST_URI'];
if ( strstr( $currentpage, "term1") )
{
$match = FALSE;
}
if ( strstr( $currentpage, "term2") )
{
$match = FALSE;
}

even better if you can combine this as well:

if (drupal_is_front_page())
{
$match = FALSE;
}

Re: Combine these

Posted: Fri Feb 24, 2012 1:51 pm
by mikosiko
is there something that couldn't be solved with a Logical Operator ?

Re: Combine these

Posted: Fri Feb 24, 2012 1:55 pm
by mealto
I think yes but I just cannot get the syntax right. Any help would be appreciated. Want to streamline this to decrease server load.

Re: Combine these

Posted: Sat Feb 25, 2012 5:13 am
by jraede
Consolidating this will not likely have a noticeable effect on server performance - it's just a few lines. However, you can do something like this:

Code: Select all

$match = (!in_array($currentpage, array('term1', 'term2')))
This means that if the value of $currentpage is in that array, set $match to FALSE, and if not, set to TRUE.

Re: Combine these

Posted: Sun Feb 26, 2012 1:14 pm
by mealto
I could not get your suggestion to work. Do you have the full syntax?

I was however able to get this to work but would still like to learn your array method. Seems it would be more efficient?

$currentpage = $_SERVER['REQUEST_URI'];
if (strstr( $currentpage, "term1") || strstr( $currentpage, "term2"))
{
$match = FALSE;
}