Parse, build and manipulate URLs.
use Myerscode\Utilities\Web\UriUtility;
$utility = new UriUtility('https://example.com/path?foo=bar#section');Get the host component.
$utility->host(); // 'example.com'Get the URL scheme.
$utility->scheme(); // 'https'Check if the URL uses HTTPS.
$utility->isHttps(); // trueGet the port (defaults to 80 for HTTP, 443 for HTTPS).
$utility->port(); // 443Get the URL path.
$utility->path(); // '/path'Get the raw query string.
$utility->query(); // 'foo=bar'Get the URL fragment (the part after #).
$utility->fragment(); // 'section'Get query parameters as an associative array.
$utility->getQueryParameters(); // ['foo' => 'bar']Append query parameters (does not override existing keys).
$utility->addQueryParameter(['baz' => 'qux']);
$utility->addQueryParameter('baz=qux');Merge query parameters (overrides existing keys).
$utility->mergeQuery(['foo' => 'updated']);Replace the entire query string.
$utility->setQuery(['new' => 'value']);Remove a specific query parameter by key.
$utility->removeQueryParameter('foo');Check if a query parameter exists.
$utility->hasQueryParameter('foo'); // trueSet or replace the URL scheme.
$utility->withScheme('http');Set or replace the URL host.
$utility->withHost('other.com');Set or replace the URL path.
$utility->withPath('/new/path');Set or replace the URL port. Pass null to remove.
$utility->withPort(8080);Set or replace the URL fragment.
$utility->withFragment('top');Get the user info component of the URI, or null if not present.
$utility->userInfo(); // nullCheck if the URL is valid without making a request.
$utility->isValid(); // trueGet all parsed URL components as an associative array.
$utility->toArray();
// ['scheme' => 'https', 'host' => 'example.com', 'port' => 443, 'path' => '/path', 'query' => 'foo=bar', 'fragment' => 'section']Compare two URIs for equality.
$a = new UriUtility('https://example.com');
$b = new UriUtility('https://example.com');
$a->equals($b); // trueCheck the URL response using curl, headers, or HTTP client.
use Myerscode\Utilities\Web\Data\ResponseFrom;
$response = $utility->check(ResponseFrom::CURL);
$response->code(); // 200Get the full URL string.
$utility->value(); // 'https://example.com/path?foo=bar#section'