Page 1 of 1

Using PHP String functions

Posted: Sat Feb 28, 2009 4:30 pm
by socket1
I need some help combining PHP string manipulation functions in order to take a path:
./Test/Path/123/456/

and taking away the last folder part so it looks like this:

./Test/Path/123/

Maybe its just that I'm tired and have been working on this the whole day but nothing will work.

All I managed to do was turn the path into .TestPath123 which won't work at all for what I need.

Re: Using PHP String functions

Posted: Sat Feb 28, 2009 5:26 pm
by requinix
There's a function for that. Doesn't keep the trailing slash in case you really want that.

Re: Using PHP String functions

Posted: Sat Feb 28, 2009 5:29 pm
by php_east

Code: Select all

 
$a='./Test/Path/123/456/';
echo $a.'<br />';
 
$a  = substr($a,0,strrpos($a,'/',-1));
$a  = substr($a,0,(strrpos($a,'/',0)+1));
 
echo $a.'<br />';
 
probably many other ways to do it too.

Re: Using PHP String functions

Posted: Sat Feb 28, 2009 5:35 pm
by socket1
tasairis, thank you... I can easily add a / ---- .'/'

I just can't believe that I spent 3 hours trying to figure out how to do the same thing.

Re: Using PHP String functions

Posted: Sat Feb 28, 2009 7:42 pm
by socket1
I used the code in my directory listing script http://aband0ned.net/
Any comments / questions / suggestions can go to socket1@aband0ned.net

Any ideas to prevent http://aband0ned.net/?dir=../ that ?