Graby\Graby::makeAbsoluteAttr PHP Method

makeAbsoluteAttr() private method

Make an attribute absolute (href or src).
private makeAbsoluteAttr ( string $base, DOMNode $e, string $attr )
$base string The base url
$e DOMNode Element on which we'll retrieve the attribute
$attr string Attribute that contains the url to absolutize
    private function makeAbsoluteAttr($base, \DOMNode $e, $attr)
    {
        if (!$e->attributes->getNamedItem($attr)) {
            return;
        }
        // Trim leading and trailing white space. I don't really like this but
        // unfortunately it does appear on some sites. e.g.  <img src=" /path/to/image.jpg" />
        $url = trim(str_replace('%20', ' ', $e->getAttribute($attr)));
        $url = str_replace(' ', '%20', $url);
        if (!preg_match('!https?://!i', $url)) {
            if ($absolute = \SimplePie_IRI::absolutize($base, $url)) {
                $e->setAttribute($attr, $absolute);
            }
        }
    }