php8.5
Home/ Manual/ whatwg / url/ Uri\WhatWg\Url::equals

Uri\WhatWg\Url::equals

PHP function Edit on GitHub ✎

(PHP 8 >= 8.5.0)

Check if two URLs are equivalent

Description

Uri\WhatWg\Url::equals(Uri\WhatWg\Url $url, Uri\UriComparisonMode $comparisonMode = Uri\UriComparisonMode::ExcludeFragment): bool

Checks if two URLs are equivalent.

Parameters

url

URL to compare the current URL against.

comparisonMode

Whether the fragment component is taken into account of the comparison (Uri\UriComparisonMode::IncludeFragment) or not (Uri\UriComparisonMode::ExcludeFragment). By default, the fragment is excluded.

Return Values

Returns true if the two URLs are equivalent, or false otherwise.

Examples

Uri\WhatWg\Url::equals basic example

php
<?php
$url1 = new \Uri\WhatWg\Url("https://example.com");
$url2 = new \Uri\WhatWg\Url("HTTPS://example.com");

var_dump($url1->equals($url2));
?>

The above example will output:

output
bool(true)

See Also

  • Uri\Rfc3986\Uri::equals

Source: reference/uri/uri/whatwg/url/equals.xml · from the official PHP manual (php/doc-en)