Reputation: 6052
I have the following URL format:
http://www.domain.com/admin/?i=page
And on sub-pages, this is the format:
http://www.domain.com/admin/?i=page&n=subpage
When echoing $_SERVER["REQUEST_URI];
I get the following:
/admin/?i=page
I am trying to show an .active
class whenever the page is active like this:
if(preg_match ('#^/admin/?i=page', $_SERVER['REQUEST_URI'])){echo "active";}
However, the active
class isn't triggered. What am I doing wrong?
Upvotes: 0
Views: 145
Reputation: 59
You are missing a delimiter in the end of the regular expression. Moreover , '?' should be escaped :
#^/admin/\?i=page#
Upvotes: 1
Reputation: 174696
You forget to escape ?
if(preg_match ('#^/admin/\?i=page#', $_SERVER['REQUEST_URI'])){echo "active";}
Upvotes: 2