ivrok/urlmanager

URLManager:高效的PHP URL解析和管理,包含处理组件和URL解析的类。

1.0.2 2024-05-10 14:56 UTC

This package is auto-updated.

Last update: 2024-09-11 04:47:14 UTC


README

URLManager 是一个PHP包,旨在简化URL的解析和管理。它包含两个类,URLURLHelper,分别用于处理URL组件和解析。

安装

您可以通过Composer安装此包

composer require ivrok/urlmanager

用法

URL类

URL 类提供了设置和获取URL组件(如协议、域名和路径)的方法。它还允许您添加查询参数。

use Ivrok\URLManager\URL;

$url = new URL('example.com');
$url->setHTTPS();
$url->setPath('/index.php');
$url->addQueryParameter('key', 'value');

echo $url; // Outputs: https://example.com/index.php?key=value

URLHelper类

URLHelper 类包括与URL对象交互的方法

use Ivrok\URLManager\URLHelper;

$url = URLHelper::parseUrl('https://www.example.com/index.php?key=value');

// Check if a specific query exists
echo URLHelper::hasQuery($url, 'key'); // Outputs: true

// Check if the URL path matches a specific path
echo URLHelper::isPath($url, '/about'); // Outputs: true

// Check if the URL path includes a specific string
echo URLHelper::isPathInclude($url, 'ab'); // Outputs: true

// Check if the domain matches
echo URLHelper::isDomain($url, 'www.example.com'); // Outputs: true

// Check if the domain and top domain matches
echo URLHelper::isDomainOrTopDomain($url, 'example.com'); // Outputs: true

特性

  • 设置和获取URL组件,如域名、路径和协议。
  • 向URL添加单个或多个查询参数。
  • 将URL字符串解析为URL对象。

许可证

URLManager 是开源软件,使用 MIT 许可协议 许可。