Assign Variable from Directory name?

by 4 replies
6
For example :
In : ttp://www.ovationmortgageloans.com/jacksonville%20mortgage%20rates.html
<?php
$keyword = preg_replace("/_/",' ',$_REQUEST["keyword"]);
?>
Gets the term before the .html so everywhere I place <?php echo $keyword; ?> on the page that term will show up.

Can this be done for a static directory :
mysite.com/florida/jacksonville%20mortgage%20rates.html
So that I could place something like <? echo $dir; ?> and the intended directory name would show up everywhere that code is placed?

Thanks!
#programming #assign #directory #variable
  • In PHP, the variable $_SERVER['PHP_SELF'] contains the file name and directory path.
    I'll leave it up to you how to parse out the info you want.
    For more, please see:
    PHP: $_SERVER - Manual
    • [ 1 ] Thanks
  • One more hint that might comes handy when you are parsing out the info you want:

    PHP: basename - Manual
    • [ 1 ] Thanks
    • [1] reply

    • lol, or you can do this: tulsatechi.com/rates/

      here is the code you put at the top of your files

      <? include($_SERVER['DOCUMENT_ROOT'].'/rates/includes/pages.php');?>

      <?
      $location = $_SERVER['PHP_SELF'];
      $location = str_replace("/rates/","",$location);
      $location = str_replace('/',' ',$location);
      $location = str_replace(".php",'',$location);
      $location = str_replace("index",'',$location);
      $location = ucwords($location);
      ?>

      I just made it an include in the example so i wouldnt have to add that to all the other files. Also, the 2nd line there just removes the main directory

      if that wasnt there it would show rates texas file name

      hope this helps ya

      OH just <? echo $location;?>

      and you dont have to use the include.. just put the source at the top of your files and it will work
      • [ 1 ] Thanks
  • Thanks everyone. I do not know PHP, just how the play with the code a little, so very helpful.

Next Topics on Trending Feed