Example #1
0
 /**
  * Make uri object from relative path string
  * @param string $uriString Relative url
  * @return uri
  */
 public static function fromString($uriString)
 {
     $uri = new uri();
     $qpos = strpos($uriString, '?');
     $get = '';
     if ($qpos !== false) {
         $get = substr($uriString, $qpos + 1);
         $uriString = substr($uriString, 0, $qpos);
     }
     $geta = explode("&", $get);
     $args = array();
     foreach ($geta as $gv) {
         @(list($k, $v) = explode("=", $gv));
         $args[$k] = $v;
     }
     // cut index.php
     $path = explode("/", $uriString);
     foreach ($path as $k => $v) {
         if ($v == '') {
             unset($path[$k]);
         } else {
             $path[$k] = urldecode($v);
         }
     }
     foreach ($args as $k => $v) {
         if ($v == '') {
             unset($args[$k]);
         }
     }
     $uri->setPath($path);
     $uri->setArgs($args);
     return $uri;
 }