Пример #1
0
function makeAbsoluteStr($base, $url)
{
    $base = new IRI($base);
    // remove '//' in URL path (causes URLs not to resolve properly)
    if (isset($base->ipath)) {
        $base->ipath = preg_replace('!//+!', '/', $base->ipath);
    }
    if (preg_match('!^https?://!i', $url)) {
        // already absolute
        return $url;
    } else {
        $absolute = IRI::absolutize($base, $url);
        if ($absolute) {
            return $absolute;
        }
        return false;
    }
}
function makeAbsoluteAttr($base, $e, $attr)
{
    if ($e->hasAttribute($attr)) {
        // 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)) {
            $absolute = IRI::absolutize($base, $url);
            if ($absolute) {
                $e->setAttribute($attr, $absolute);
            }
        }
    }
}