Let’s say if the user is able to select some directories to search. And he checkmarks the following directories below:
http://google.com/apple
http://google.com/apple/red
http://google.com/apple/green
http://google.com/apple/yellow
http://google.com/orange
http://google.com/orange/1
When getting ready to insert this data in lets say a database. Is there a way so I can simplify the list via PHP in order to show something like below:
http://google.com/apple
http://google.com/orange
Thanks
Cyrus
This should do the trick:
This code relies on the fact that a string sorts just before any extensions of itself. Note that it doesn’t treat slashes in any special way, and so it considers, say,
"quux/foo"to be a valid prefix of"quux/foobar"(and this is not as easy to fix properly as I first thought it would be). If you don’t want that, make sure your paths have trailing slashes where appropriate.