Documentation for crwlr / url (v1.2)

Attention: You're currently viewing the documentation for v1.2 of the url package.
This is not the latest version of the package.
If you didn't navigate to this version intentionally, you can click here to switch to the latest version.

Comparing Urls or Url Components

You may think to compare two urls you don't need this library, but whenever you have urls from an unpredictable input source, I'd recommend using it. Imagine a case like this:

$url1 = 'ár/báz';
$url2 = '';

var_dump($url1 === $url2);
// Returns false. Of course the two strings aren't equal.

// Returns true, because the path /foo/bár/báz is percent-encoded
// in the Url class to /foo/b%C3%A1r/b%C3%A1z

It's also really easy to compare the same component of two different urls.

$url1 = Url::parse('');
$url2 = Url::parse('');
$url3 = clone $url1;

$url1->isSchemeEqualIn($url2); // false
$url1->isSchemeEqualIn($url3); // true

$url1->isHostEqualIn($url2); // false
$url1->isHostEqualIn($url3); // true

$url1->isPasswordEqualIn($url2); // false
$url1->isPasswordEqualIn($url3); // true

These are all available comparison methods:

  • isEqualTo($url)
  • isComponentEqualIn($url, $componentName)
  • isSchemeEqualIn($url)
  • isAuthorityEqualIn($url)
  • isUserEqualIn($url)
  • isPasswordEqualIn($url)
  • isUserInfoEqualIn($url)
  • isHostEqualIn($url)
  • isDomainEqualIn($url)
  • isDomainLabelEqualIn($url)
  • isDomainSuffixEqualIn($url)
  • isSubdomainEqualIn($url)
  • isPortEqualIn($url)
  • isPathEqualIn($url)
  • isQueryEqualIn($url)
  • isFragmentEqualIn($url)