当前位置: 首页>>代码示例>>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;未经允许,请勿转载。