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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux