Hi guys, this is what im trying to achieve, im trying to remove the links to the current page for all my web pages with a single script, like for example, if i am on a home page, then the home page hyperlink is disabled, and if i am on a about us page the hyperlink for about us is disabled, i have went through many forums and posts but the more i read the more confused i get, however i came up with a method of my own with many bits of code i've read about everywhere.
firstly, the script collects the current url of the page(i dont need https or any sub direct, its just for example index.php)
then it stores the page name, index.php into a variable say - $current
Then a menu.php which is the navigation file is loaded and heres the part i cant get to work, i would like to match find that <a href="index.php"> index </a> and replace that with <a> index </>
so that the link to the current page is disabled..i tried using preg_replace but failed miserably and opted to use str_replace
Heres the code:
<?php
//the function below gets the current page url or file
//i got this off webcheatsheet - http://www.webcheatsheet.com/PHP/get_current_page_url.php
function getPage(){
return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}
//store the current url or the file name into a variable
$current = getPage();
echo "The current page name is ".$current;
$menu=file_get_contents("menu.php");
$string = "<a>"+$current+"</a>";
$link = "<a href="+ current +"> ";
//i could not get preg_replace to work or come up with an effective regular expression
//which is why i use str_replace instead.
$menu=str_replace("" , $string, $menu);
echo $menu;
?>