unexpected 'OR' (T_LOGICAL_OR)

4k Views Asked by At

I've been trying to make an "active" state in Bootstrap, giving li a class="active" whenever it's on the specified site.

I have this script:

<?php if (stripos($_SERVER['REQUEST_URI'],'/page1.php') !== false) OR (stripos($_SERVER['REQUEST_URI'],'/page2.php') !== false) {echo 'active';} ?>

It's used for a dropdown, that should have the active class whenever it's on either page1 or page2.

I get this error:

Parse error: syntax error, unexpected 'OR' (T_LOGICAL_OR) in your code on line 1

Does anyone know what I've done wrong here? I've tried with "OR" and "||", but none of them work.

3

There are 3 best solutions below

5
On BEST ANSWER

The if statement is incorrectly formatted

<?php if ((stripos($_SERVER['REQUEST_URI'],'/page1.php') !== false) OR (stripos($_SERVER['REQUEST_URI'],'/page2.php') !== false)) {echo 'active';} ?>
1
On

Remove the brakets before and after the OR like below.

<?php if (stripos($_SERVER['REQUEST_URI'],'/page1.php') !== false OR stripos($_SERVER['REQUEST_URI'],'/page2.php') !== false) {echo 'active';} ?>

0
On
<?php if ((stripos($_SERVER['REQUEST_URI'],'/page1.php') !== false) OR (stripos($_SERVER['REQUEST_URI'],'/page2.php') !== false)) echo 'active'; ?>

This code works - I've tried it!

One missing set of brackets and one superflous set.