Combine these

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mealto
Forum Newbie
Posts: 3
Joined: Fri Feb 24, 2012 1:25 pm

Combine these

Post 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;
}
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: Combine these

Post by mikosiko »

is there something that couldn't be solved with a Logical Operator ?
mealto
Forum Newbie
Posts: 3
Joined: Fri Feb 24, 2012 1:25 pm

Re: Combine these

Post 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.
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Re: Combine these

Post 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.
mealto
Forum Newbie
Posts: 3
Joined: Fri Feb 24, 2012 1:25 pm

Re: Combine these

Post 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;
}
Post Reply