Re: point me to functions to parse the URL? (best one for *this*job?)

From: Date: Fri, 26 Jun 2009 06:53:47 +0000
Subject: Re: point me to functions to parse the URL? (best one for *this*job?)
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-294634@lists.php.net to get a copy of this message
On Thu, 25 Jun 2009 18:20:36 -0500, Shawn McKenzie wrote: > Shawn McKenzie wrote: >> Govinda wrote: >>> I need to parse those URLs and set the value of $myfolder to as follows: >>> >>> domain.com/unix/asdfsdf.html >>> $myfolder=unix >>> domain.com/macos/khsdfg.html >>> $myfolder=macos >>> >>> BUT if there is no dir/ in between the domain and file, >>> like so: >>> domain.com/khsdfg.html >>> then I want: >>> $myfolder=default >> >> No way, you want to "parse" the "url"? >> >> How about, parse_url()? Or something like: /* UNTESTED */ $myfolder = 'default'; if (preg_match ('@^[^/]+/([^/]+)/@', $url, $m) { $myfolder = $m[1]; } or: /* UNTESTED */ $myfolder = 'default'; $parts = explode ('/', $url); if (count ($parts) > 2) { $myfolder = $parts[1]; } > Oh, and in the future, if you want to "strip" the "slashes" from a var, > you would use the remove_escape_char() function :-) Is there a manual page for that? /Nisse

« previous php.general (#294634) next »