Link to home
Start Free TrialLog in
Avatar of morako
morakoFlag for United States of America

asked on

How do I create variables for each directory in a string?

I am trying to create variables for directories to be used later within the site as titles.

<?php echo $title_1 ?>

<?php echo $title_2 ?>

from          /dir1/dir2/dir3

So far I am able to pick up the first title in the directory but having problems extracting the second or third titles...  Below is where I am...

Any thoughts?

<?
    if($location = substr(dirname($_SERVER['PHP_SELF']), 1))
        $dirlist = explode('/', $location);
    else
        $dirlist = array();
    
    $count = array_push($dirlist, basename($_SERVER['PHP_SELF']));
    
    $address = 'http://'.$_SERVER['HTTP_HOST'];
    
    for($i = 0; $i < $count; $i++)
    
         ($activepath .= str_replace("index.php","",'/'.  $dirlist[$i]));
    
    $value = $activepath;
    $topdir = strtok($value, " / ");
    $title_1 = ucwords($topdir);
    
    
    $value2 = $activepath;
    $secdir .= str_replace("/", "", " ", strtok($value2, " / "))  ;
    $title_2 = ucwords($secdir);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of James Williams
James Williams
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of morako

ASKER

Thanks..  ;-)