homepage Welcome to WebmasterWorld Guest from 54.243.12.156
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Needed Explode Command
branmh




msg:1246726
 2:34 pm on Jan 12, 2006 (gmt 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

 

LeChuck




msg:1246727
 2:44 pm on Jan 12, 2006 (gmt 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

branmh




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

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

LeChuck




msg:1246729
 3:35 pm on Jan 12, 2006 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved