Documentation for crwlr / url (v2.1)

Resolving Relative Urls

When you scrape urls from a website you will come across relative urls like /path/to/page, ../path/to/page, ?param=value, #anchor and alike. This package makes it a breeze to resolve these urls to absolute ones with the url of the page where they have been found on.

$documentUrl = Url::parse('');

$relativeLinks = [

$absoluteLinks = array_map(function($relativeLink) use ($documentUrl) {
    return $documentUrl->resolve($relativeLink)->toString();
}, $relativeLinks);



array(4) {
  string(36) ""
  string(40) ""
  string(47) ""
  string(42) ""

If you pass an absolute url to resolve() it will just return that absolute url.