Welcome to WebmasterWorld Guest from 54.221.87.97

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Needed Explode Command

     

branmh

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

10+ Year Member



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

LeChuck

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

5+ Year Member



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

branmh

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

10+ Year Member



The /dir1/dir2/ would be in the url, so how do this?

LeChuck

3:35 pm on Jan 12, 2006 (gmt 0)

5+ Year Member



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.