[PHP] Re: point me to functions to parse the URL? (best one for *this*job?)
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: point me to functions to parse the URL? (best one for *this* job?)
Govinda wrote: Hi all, (PHP newbie here. Newbie-level task to match.) I am RTFM and working on this.. but I am also under deadline, so, I ask you in case you can point me quick where to read... what functions I need to use for this. Incoming URL will look like these, for example: domain.com/unix/asdfsdf.html domain.com/macos/khsdfg.html 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 I am playing with $_SERVER['PATH_TRANSLATED'], .. what function will parse that best? I need to also account for when the URL does not have an in-between dir/, nor a filename in it, e.g.: domain.com/ (then again $myfolder=default) TIA! -Govinda No way, you want to parse the url? How about, parse_url()? -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: point me to functions to parse the URL? (best one for *this*job?)
Shawn McKenzie wrote: Govinda wrote: Hi all, (PHP newbie here. Newbie-level task to match.) I am RTFM and working on this.. but I am also under deadline, so, I ask you in case you can point me quick where to read... what functions I need to use for this. Incoming URL will look like these, for example: domain.com/unix/asdfsdf.html domain.com/macos/khsdfg.html 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 I am playing with $_SERVER['PATH_TRANSLATED'], .. what function will parse that best? I need to also account for when the URL does not have an in-between dir/, nor a filename in it, e.g.: domain.com/ (then again $myfolder=default) TIA! -Govinda No way, you want to parse the url? How about, parse_url()? Oh, and in the future, if you want to strip the slashes from a var, you would use the remove_escape_char() function :-) -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: point me to functions to parse the URL? (best one for *this*job?)
Shawn McKenzie wrote: Shawn McKenzie wrote: Govinda wrote: Hi all, (PHP newbie here. Newbie-level task to match.) I am RTFM and working on this.. but I am also under deadline, so, I ask you in case you can point me quick where to read... what functions I need to use for this. Incoming URL will look like these, for example: domain.com/unix/asdfsdf.html domain.com/macos/khsdfg.html 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 I am playing with $_SERVER['PATH_TRANSLATED'], .. what function will parse that best? I need to also account for when the URL does not have an in-between dir/, nor a filename in it, e.g.: domain.com/ (then again $myfolder=default) TIA! -Govinda No way, you want to parse the url? How about, parse_url()? Oh, and in the future, if you want to strip the slashes from a var, you would use the remove_escape_char() function :-) Sorry, after actually reading your post, and having nothing else to do at the moment (one solution): $myfolder = basename(dirname($_SERVER['PHP_SELF'])); if(empty($myfolder)) { $myfolder = 'default'; } -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php