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

Reply via email to