First sorry for my bad English.
I have this menubar in PHP. I want that if an user is on a page the current menuitem gets another color. I had a code that works, but if i have a page like /item.php?id=9 , it wont work. So i tried this with preg_match, but i can't get it to work.
Menu :
<li <?php unset($pageURL); getSelected("/index.php") ?>><a href="index.php">Home</a></li>
<li <?php unset($pageURL); getSelected("/item.php") ?>><a href="item.php">Item</a></li>
<li <?php unset($pageURL); getSelected("/more.php") ?>><a href="more.php">More</a></li>
Function getSelected:
Function getSelected($nameURL){
$curURL =$_SERVER["REQUEST_URI"];
$pattern = "~$nameURL/.*~";
if(preg_match($pattern, $curURL)){
echo 'class="selected"';
unset($curURL);
}
unset($curURL);
}
How can i fix this with preg_match?
Thank you!