scholte/uri

此包最新版本(1.1.2)无可用许可证信息。

RFC 3986 PHP URI 扩展

1.1.2 2019-07-31 21:40 UTC

This package is auto-updated.

Last update: 2024-09-29 04:49:20 UTC


README

此对象遵循在 http://www.php-fig.org/psr/psr-7/RFC 3986 中描述的 PSR-7 HTTP 消息。每个 URI 都有如下所示的特定结构

tel:+31-123-456-789
urn:oasis:names:specification:docbook:dtd:xml:4.1.2
ftp://ftp.is.co.za/rfc/rfc1808.txt
mailto:John.Doe@example.com
scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]
  1. 协议: schema
  2. 认证: 用户:密码
  3. 域名: www.host.com
  4. 端口: 80
  5. 路径: /path
  6. 查询: ?参数=值
  7. 片段: #片段

安装

可以使用 composer 安装此包

$ composer require scholte/uri

如何使用

URI 对象可用于所有 RFC 3986 URI。可以更改或提取 URI 的特定部分,而无需搜索和替换这些部分。

<?php
use Scholte\Uri;

$uri = new Uri('scheme://user:password@www.host.com:80/path?parameter=value#fragment');
echo $uri->setScheme('https')->getUri(URI_STRIP_FRAGMENT);
// Output: https://user:password@www.host.com/path?parameter=value

$uri = new Uri('http://www.host.com/path');
echo $uri->getUri(URI_STRIP_SCHEME|URI_STRIP_HOST);
// Output: /path

关于

依赖

  • 支持 PHP 7.1 或更高版本
  • psr/http-message ^1.0

作者

Christiaan Scholte - cscholte_83@hotmail.com