当前位置: 首页>>代码示例>>PHP>>正文


PHP Uri::parse方法代码示例

本文整理汇总了PHP中Zend\Uri\Uri::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP Uri::parse方法的具体用法?PHP Uri::parse怎么用?PHP Uri::parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Uri\Uri的用法示例。


在下文中一共展示了Uri::parse方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: benchmark

 /**
  * @inheritdoc
  */
 public function benchmark($count, $uri)
 {
     $start = microtime(true);
     $memory = memory_get_usage();
     $uriParser = new Uri(null);
     foreach ($this->generateUri($count, $uri) as $url) {
         $uriParser->parse($url);
     }
     return ['memory' => memory_get_usage() - $memory, 'duration' => microtime(true) - $start];
 }
开发者ID:nyamsprod,项目名称:uri-parser-benchmarks,代码行数:13,代码来源:Zend.php

示例2: getThumbs

 /**
  * Get a list of thumbs from a URI
  * @param string $uri
  * @param integer $limit
  * @return array
  */
 public function getThumbs($uri, $limit = 5)
 {
     $validator = new \Zend\Validator\Uri(array('allowRelative' => false));
     $return = array();
     if ($validator->isValid($uri)) {
         $parseInfo = parent::parse($uri);
         switch ($parseInfo->host) {
             // Youtube.com
             case "www.youtube.com":
                 $queryArray = array();
                 parse_str($parseInfo->query, $queryArray);
                 if (isset($queryArray['v'])) {
                     $return = array("http://img.youtube.com/vi/" . $queryArray['v'] . "/0.jpg", "http://img.youtube.com/vi/" . $queryArray['v'] . "/1.jpg", "http://img.youtube.com/vi/" . $queryArray['v'] . "/2.jpg", "http://img.youtube.com/vi/" . $queryArray['v'] . "/3.jpg");
                 }
                 break;
                 // Dailymotion.com
             // Dailymotion.com
             case "www.dailymotion.com":
                 if (strpos($parseInfo->path, "/video") !== false) {
                     $return = array('http://www.dailymotion.com/thumbnail' . $parseInfo->path);
                 }
                 break;
                 // Vimeo.com
             // Vimeo.com
             case "vimeo.com":
                 $id = str_replace("/", "", $parseInfo->path);
                 $data = \Zend\Json\Json::decode(file_get_contents("http://vimeo.com/api/v2/video/{$id}.json"));
                 $return = array($data[0]->thumbnail_medium);
                 break;
                 // others webpage
             // others webpage
             default:
                 /**
                  * Credit to http://www.bitrepository.com
                  * http://www.bitrepository.com/extract-images-from-an-url.html
                  */
                 // Fetch page
                 $string = $this->fetchPage($uri);
                 $out = array();
                 // Regex for SRC Value
                 $image_regex_src_url = '/<img[^>]*' . 'src=[\\"|\'](.*)[\\"|\']/Ui';
                 preg_match_all($image_regex_src_url, $string, $out, PREG_PATTERN_ORDER);
                 $return = $out[1];
                 for ($i = 0; $i < count($return); $i++) {
                     $tUri = new Uri();
                     $parseInfoThumb = $tUri->parse($return[$i]);
                     if (!$parseInfoThumb->isAbsolute()) {
                         $return[$i] = $parseInfo->scheme . "://" . $parseInfo->host . "" . $return[$i];
                     }
                 }
         }
     }
     // check && return
     return array_slice($return, 0, $limit);
 }
开发者ID:remithomas,项目名称:rt-extends,代码行数:61,代码来源:Thumb.php

示例3: getType

 /**
  * 
  * @param string $uri
  * @return string
  */
 public function getType($uri)
 {
     $validator = new \Zend\Validator\Uri(array('allowRelative' => false));
     if ($validator->isValid($uri)) {
         $parseInfo = parent::parse($uri);
         switch ($parseInfo->host) {
             // Youtube.com
             case "www.youtube.com":
                 $queryArray = array();
                 parse_str($parseInfo->query, $queryArray);
                 if (isset($queryArray['v'])) {
                     return self::TYPE_VIDEO_YOUTUBE;
                 }
                 break;
                 // Dailymotion.com
             // Dailymotion.com
             case "www.dailymotion.com":
                 if (strpos($parseInfo->path, "/video") !== false) {
                     return self::TYPE_VIDEO_DAILYMOTION;
                 }
                 break;
                 // Vimeo.com
             // Vimeo.com
             case "vimeo.com":
                 if (is_int($parseInfo->path)) {
                     return self::TYPE_VIDEO_VIMEO;
                 }
                 break;
         }
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $uri);
         curl_setopt($ch, CURLOPT_HEADER, TRUE);
         curl_setopt($ch, CURLOPT_NOBODY, TRUE);
         // remove body
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
         $head = curl_exec($ch);
         $contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
         curl_close($ch);
         if (strpos($contentType, "image") !== false) {
             return self::TYPE_IMAGE;
         } else {
             if ($contentType == "application/x-shockwave-flash") {
                 return self::TYPE_SWF;
             }
         }
         return self::TYPE_WEBPAGE;
     } else {
         return "";
     }
 }
开发者ID:remithomas,项目名称:rt-extends,代码行数:55,代码来源:Type.php

示例4: getRedirect

 public function getRedirect($urlString, $stayLocal = true, $preserveHttps = true)
 {
     /**
      * Check that the URL has the correct format expected of a valid HTTP
      * or HTTPS URL. If so, normalize the URL.
      */
     $valid = false;
     $url = new Uri();
     try {
         $url->parse($urlString);
         if ($url->isValid() && $url->isAbsolute()) {
             $url->normalize();
             $valid = true;
         }
     } catch (\Exception $e) {
     }
     if (false === $valid) {
         throw new Exception\InvalidArgumentException("Given value was not a valid absolute HTTP(S) URL: " . $url);
     }
     /**
      * Make sure we don't redirect from HTTPS to HTTP unless flagged by
      * the user. Using a Strict-Transport-Security header helps too!
      */
     if (true === (bool) $preserveHttps && HttpsDetector::isHttpsRequest()) {
         if (!$this->isHttps($url)) {
             throw new Exception\InvalidArgumentException("Given value was not a HTTPS URL as expected: " . $url);
         }
     }
     /**
      * Check if the URL meets the local host restriction unless disabled
      */
     if (true === $stayLocal && !$this->isLocal($url)) {
         throw new Exception\InvalidArgumentException("Given value was not a local HTTP(S) URL: " . $url);
     }
     /**
      * Check if the URL host exists on a whitelist of allowed hosts
      */
     $whitelist = $this->getWhitelist();
     if (!empty($whitelist) && !$this->isWhitelisted($url)) {
         throw new Exception\InvalidArgumentException("Given value was not a whitelisted URL as expected: " . $url);
     }
     /**
      * Get URL string after URL encoding checks and return a Location header
      * object.
      */
     $header = new Header\Location(array('url' => $url->toString(), 'status_code' => 302));
     return $header;
 }
开发者ID:emma5021,项目名称:toba,代码行数:48,代码来源:Redirector.php

示例5: testParseTwice

 public function testParseTwice()
 {
     $uri = new Uri();
     $uri->parse('http://user@example.com:1/absolute/url?query#fragment');
     $uri->parse('/relative/url');
     $this->assertNull($uri->getScheme());
     $this->assertNull($uri->getHost());
     $this->assertNull($uri->getUserInfo());
     $this->assertNull($uri->getPort());
     $this->assertNull($uri->getQuery());
     $this->assertNull($uri->getFragment());
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:12,代码来源:UriTest.php

示例6: parse

 /**
  * Parse a URI string
  *
  * @param  string $uri
  * @return \Zend\Uri\Uri
  */
 public function parse($uri)
 {
     return $this->uri->parse($uri);
 }
开发者ID:sunnyct,项目名称:silexcmf-core,代码行数:10,代码来源:Uri.php

示例7: parse

 /**
  * Parse a URI string
  *
  * @access public
  * @param  string $uri
  * @return Uri
  */
 public function parse($uri)
 {
     $this->uri = $uri;
     return parent::parse($uri);
 }
开发者ID:camelcasetechsd,项目名称:certigate,代码行数:12,代码来源:Uri.php


注:本文中的Zend\Uri\Uri::parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。