peterpostmann/resolve_uri

解析相对URL,就像浏览器一样

1.0.0 2017-11-17 15:53 UTC

This package is not auto-updated.

Last update: 2024-09-15 04:07:13 UTC


README

Software License Build Status

解析相对URL,就像浏览器一样。

此函数基于基本路径(RFC3986 URL、URN、Windows路径、相对路径或文件)和新的路径返回一个新的URI。

安装

通过Composer

composer require peterpostmann/resolve_uri

如果您不想使用Composer,请复制resolve_uri.php文件和[peterpostmann\php-parse_uri][2]中的parse_uri.php文件,并将其包含到您的项目中。

用法

use function peterpostmann\uri\resolve_uri;

string resolve_uri ( string basePath, string newPath) 

示例

解析URI

use function peterpostmann\uri\resolve_uri;

echo resolve_uri('http://a/b/c/d;p?q#x',    'x')."\n";
echo resolve_uri('C:\path\file1.ext',       'file2.ext')."\n";
echo resolve_uri('file://smb/path/to/file', '/new/path/x.ext')."\n";

上述示例将输出

http://a/b/c/x
C:\path\file2.ext
file://smb/new/path/x.ext

许可

MIT许可(MIT)。有关更多信息,请参阅许可文件