Documentation for crwlr / url (v0.1)

Attention: You're currently viewing the documentation for v0.1 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.

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.