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


PHP WP_Http::parse_url方法代碼示例

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


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

示例1: make_absolute_url

 /**
  * Converts a relative URL to an absolute URL relative to a given URL.
  *
  * If an Absolute URL is provided, no processing of that URL is done.
  *
  * @since 3.4.0
  *
  * @static
  * @access public
  *
  * @param string $maybe_relative_path The URL which might be relative
  * @param string $url                 The URL which $maybe_relative_path is relative to
  * @return string An Absolute URL, in a failure condition where the URL cannot be parsed, the relative URL will be returned.
  */
 public static function make_absolute_url($maybe_relative_path, $url)
 {
     if (empty($url)) {
         return $maybe_relative_path;
     }
     if (!($url_parts = WP_Http::parse_url($url))) {
         return $maybe_relative_path;
     }
     if (!($relative_url_parts = WP_Http::parse_url($maybe_relative_path))) {
         return $maybe_relative_path;
     }
     // Check for a scheme on the 'relative' url
     if (!empty($relative_url_parts['scheme'])) {
         return $maybe_relative_path;
     }
     $absolute_path = $url_parts['scheme'] . '://';
     // Schemeless URL's will make it this far, so we check for a host in the relative url and convert it to a protocol-url
     if (isset($relative_url_parts['host'])) {
         $absolute_path .= $relative_url_parts['host'];
         if (isset($relative_url_parts['port'])) {
             $absolute_path .= ':' . $relative_url_parts['port'];
         }
     } else {
         $absolute_path .= $url_parts['host'];
         if (isset($url_parts['port'])) {
             $absolute_path .= ':' . $url_parts['port'];
         }
     }
     // Start off with the Absolute URL path.
     $path = !empty($url_parts['path']) ? $url_parts['path'] : '/';
     // If it's a root-relative path, then great.
     if (!empty($relative_url_parts['path']) && '/' == $relative_url_parts['path'][0]) {
         $path = $relative_url_parts['path'];
         // Else it's a relative path.
     } elseif (!empty($relative_url_parts['path'])) {
         // Strip off any file components from the absolute path.
         $path = substr($path, 0, strrpos($path, '/') + 1);
         // Build the new path.
         $path .= $relative_url_parts['path'];
         // Strip all /path/../ out of the path.
         while (strpos($path, '../') > 1) {
             $path = preg_replace('![^/]+/\\.\\./!', '', $path);
         }
         // Strip any final leading ../ from the path.
         $path = preg_replace('!^/(\\.\\./)+!', '', $path);
     }
     // Add the Query string.
     if (!empty($relative_url_parts['query'])) {
         $path .= '?' . $relative_url_parts['query'];
     }
     return $absolute_path . '/' . ltrim($path, '/');
 }
開發者ID:prettygenuis,項目名稱:PURPLE-Co.,代碼行數:66,代碼來源:class-http.php

示例2: parse_url

 public static function parse_url($url)
 {
     return parent::parse_url($url);
 }
開發者ID:rclilly,項目名稱:wordpress-develop,代碼行數:4,代碼來源:http.php


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