本文整理汇总了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());
}
示例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;
}