Assign Variable from Directory name?

4 replies
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!
#assign #directory #variable
  • Profile picture of the author KirkMcD
    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
    {{ DiscussionBoard.errors[3919923].message }}
  • Profile picture of the author andrejvasso
    One more hint that might comes handy when you are parsing out the info you want:

    PHP: basename - Manual
    {{ DiscussionBoard.errors[3919987].message }}
    • Profile picture of the author newbie365
      Originally Posted by andrejvasso View Post

      One more hint that might comes handy when you are parsing out the info you want:

      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
      {{ DiscussionBoard.errors[3920508].message }}
  • Profile picture of the author scotl47
    Thanks everyone. I do not know PHP, just how the play with the code a little, so very helpful.
    {{ DiscussionBoard.errors[3920858].message }}

Trending Topics