Jump to content

Recommended Posts

Ok so I'm coding up a file tree for a script and I've got the system setup so that when a user clicks on a folder it adds that folder to the path. The path is stored in a variable, but I'd like to allow the user to be able to go down multiple directories at once. To do this I'm going to seperate each folder name in the path and link to it so as an example:

 

$path = './home/public_html/folder1/folder2';

 

how can I separate each of those so I can make a link to that folder so that:

 

/home goes to $path = './home/';

/public_html goes to $path = './home/public_html';

etc...

---

Basically just seperate the slashes into an array and seperate each of them off based on how far along it is but I don't know how to do that...

 

Link to comment
https://forums.phpfreaks.com/topic/252869-seperate-slashes-into-links/
Share on other sites

While it's possible to write a function to do what you suggest, it may be better for you to look into opendir() or glob()

 

Just because of what you describe as your intentions.

 

The creating of new files and folders could be based off the value by simply appending to the end.

Last answer was probably best but you can break a string at a particular delimter using explode() function

 


$str = "this/is/my/str";

$myarray = explode('/', $str);

print_r($myarray);

 

That will produce an array with each value being whatever is between the slashes.

 

 

Ok so I'm coding up a file tree for a script and I've got the system setup so that when a user clicks on a folder it adds that folder to the path. The path is stored in a variable, but I'd like to allow the user to be able to go down multiple directories at once. To do this I'm going to seperate each folder name in the path and link to it so as an example:

 

$path = './home/public_html/folder1/folder2';

 

how can I separate each of those so I can make a link to that folder so that:

 

/home goes to $path = './home/';

/public_html goes to $path = './home/public_html';

etc...

---

Basically just seperate the slashes into an array and seperate each of them off based on how far along it is but I don't know how to do that...


$str = "this/is/my/str";

$myarray = explode('/', $str);

print_r($myarray);

 

That will produce an array with each value being whatever is between the slashes.

 

Well that sort of solves 1/2 my problem, but I need two things: The name of the folder and the path to the folder. So with that I can separate the name of the folder... any ideas for the path?

$current_path_array = explode('/', $current_path);
$current_path_array = array_filter($current_path_array);
echo '/';
foreach($current_path_array as $variable){
$cp = $cp.'/'.$variable;
$variable = stripslashes($variable);
echo '<a href="filemanager.php?open='.$cp.'">'.$variable.'</a>/';
}

 

Figured it out using an array, a for each and a static variable. Thanks for the help :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.