當前位置: 首頁>>代碼示例>>PHP>>正文


PHP URI::parse方法代碼示例

本文整理匯總了PHP中URI::parse方法的典型用法代碼示例。如果您正苦於以下問題:PHP URI::parse方法的具體用法?PHP URI::parse怎麽用?PHP URI::parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在URI的用法示例。


在下文中一共展示了URI::parse方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testWith

 /**
  * @dataProvider providerWith
  * @memcheck
  */
 public function testWith($uri, $method, $args, $get_method)
 {
     $uri = URI::parse($uri);
     $prev = $uri->{$get_method}();
     if (is_array($args)) {
         $uri2 = $uri->{$method}(...$args);
     } else {
         $uri2 = $uri->{$method}($args);
     }
     /* @var URI $uri2 */
     $this->assertInstanceOf('ION\\URI', $uri2);
     $this->assertNotSame($uri, $uri2);
     $this->assertSame($prev, $uri->{$get_method}());
     $this->assertNotSame($prev, $uri2->{$get_method}());
     $this->assertNotSame($uri->__toString(), $uri2->__toString());
 }
開發者ID:php-ion,項目名稱:php-ion,代碼行數:20,代碼來源:URITest.php

示例2: toAbsolute

 /**
  * Convert a URL to it's absolute URL.
  * @param string $url The url to make absolute
  * @param string $context The relative URL
  */
 public function toAbsolute($context)
 {
     // return if already absolute URL
     if (!isset($this->scheme) || $this->scheme === '') {
         $contextParsed = new URI();
         $contextParsed->parse($context);
         if ($this->url[0] === '#' || $this->url[0] === '?') {
             // queries and anchors
             $absolute = $contextParsed->url . $this->url;
         } else {
             // destroy path if relative url points to root
             if ($this->url[0] === '/') {
                 $path = '';
             } else {
                 // remove non-directory element from path
                 $path = preg_replace('#/[^/]*$#', '', $contextParsed->path);
             }
             /* dirty absolute URL */
             $absolute = $contextParsed->host . '/' . $path . '/' . $this->url;
             // replace '//' or '/./' or '/foo/../' with '/'
             $regex = array('#(/\\.?/)#', '#/(?!\\.\\.)[^/]+/\\.\\./#');
             do {
                 $n = 0;
                 $absolute = preg_replace($regex, '/', $absolute, -1, $n);
             } while ($n > 0);
             $absolute = $contextParsed->scheme . '://' . $absolute;
         }
     } else {
         $absolute = $this->url;
     }
     if (substr($absolute, -1, 1) === '/') {
         $absolute = substr($this->url, 0, strlen($this->url) - 1);
     }
     $this->url = $absolute;
     $this->parse();
     return $absolute;
 }
開發者ID:nojacko,項目名稱:twuddle-core,代碼行數:42,代碼來源:URI.php


注:本文中的URI::parse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。