Welcome to WebmasterWorld Guest from 23.22.182.29

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Needed Explode Command

     
2:34 pm on Jan 12, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Aug 6, 2003
posts:77
votes: 0


I need an explode command to brake a directory struction into variables?

Example: /dir1/dir2/

I would like dir1 to be a variable as well as dir2 but have it not to display error messages if dir2 is missing and have it not to miss up when additonal /dir#/ or filename is added.

If an explode command is what I need can you please post or if another way to do this is better than explain.

Thanks

2:44 pm on Jan 12, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 12, 2005
posts:136
votes: 0


Sure,

$string="/1/2/3";
$directories=explode("/",$string);

gives you

$directories[0]=blank
$directories[1]=1
$directories[2]=2
$directories[3]=3

remove the first slash in your string and you'll get

$directories[0]=1
$directories[1]=2
$directories[2]=3

2:54 pm on Jan 12, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Aug 6, 2003
posts:77
votes: 0


The /dir1/dir2/ would be in the url, so how do this?
3:35 pm on Jan 12, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 12, 2005
posts:136
votes: 0


My preference would be to use mod_rewrite to get them.

This does the job too, but you should validate your input:

$temp=parse_url(getenv("REQUEST_URI"));
$string=$temp["path"];

there may be more work required depending on your site.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members