Jump to content

lbj90

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Everything posted by lbj90

  1. Thanks for the reply!, yes i do have access to modify the menu.php ,but for some reasons, my output was menu.php was not changed at all when it is presented , it should have changed for example i embedded this script into home.php and home.php shouldnt be clickable if i am on that page, is something wrong with my script? or are there any alternative ways to do this such as preg_replace , i am only trying to disable users from clicking on a link that leads them to the page they are already on.
  2. 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; ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.