jj20051 Posted December 10, 2011 Share Posted December 10, 2011 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... Quote Link to comment https://forums.phpfreaks.com/topic/252869-seperate-slashes-into-links/ Share on other sites More sharing options...
QuickOldCar Posted December 10, 2011 Share Posted December 10, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/252869-seperate-slashes-into-links/#findComment-1296500 Share on other sites More sharing options...
Drongo_III Posted December 10, 2011 Share Posted December 10, 2011 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... Quote Link to comment https://forums.phpfreaks.com/topic/252869-seperate-slashes-into-links/#findComment-1296503 Share on other sites More sharing options...
jj20051 Posted December 10, 2011 Author Share Posted December 10, 2011 $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? Quote Link to comment https://forums.phpfreaks.com/topic/252869-seperate-slashes-into-links/#findComment-1296642 Share on other sites More sharing options...
jj20051 Posted December 11, 2011 Author Share Posted December 11, 2011 $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 Quote Link to comment https://forums.phpfreaks.com/topic/252869-seperate-slashes-into-links/#findComment-1296674 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.