Using PHP String functions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
socket1
Forum Commoner
Posts: 82
Joined: Mon Dec 08, 2008 7:40 pm
Location: Shokan, New York

Using PHP String functions

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Using PHP String functions

Post by requinix »

There's a function for that. Doesn't keep the trailing slash in case you really want that.
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: Using PHP String functions

Post 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.
socket1
Forum Commoner
Posts: 82
Joined: Mon Dec 08, 2008 7:40 pm
Location: Shokan, New York

Re: Using PHP String functions

Post 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.
socket1
Forum Commoner
Posts: 82
Joined: Mon Dec 08, 2008 7:40 pm
Location: Shokan, New York

Re: Using PHP String functions

Post 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 ?
Post Reply