Question

I am using simple html dom to extract data from a website and pharse it. I cannot however change one of the realative paths in the style tag to a full one. I have tried many combinations.

I found a post here to use a PEAR script with simple html dom and it has worked on all links except below.

require_once 'includes/URL2.php';

$uri = new Net_URL2('http://www.stormcinemas.ie'); // URI of the resource
$baseURI = $uri;

foreach ($htmlcss->find('background[url]') as $elem) {
    $elem->url = $baseURI->resolve($elem->url)->__toString();
}

foreach ($html->find('*[src]') as $elem) {
    $elem->src = $baseURI->resolve($elem->src)->__toString();
}
foreach ($html->find('*[href]') as $elem) {
    if (strtoupper($elem->tag) === 'BASE') continue;
    $elem->href = $baseURI->resolve($elem->href)->__toString();
}
foreach ($html->find('form[action]') as $elem) {
    $elem->action = $baseURI->resolve($elem->action)->__toString();
}

style.css

<style> 
div.spriteImgSmall { background: url(/images/css_sprites/film_sprites/smallimages_sprite.jpg); } 
</style>

Thanks

Was it helpful?

Solution

The solution was provided here but was deleted unfortunately. Thanks again, it actualy did solve my question.

Here it is for future ref.

$htmlcss = preg_replace('/url\(\s*[\'"]?\/?(.+?)[\'"]?\s*\)/i', 'url('.
        $baseURI.'/$1)', $htmlcss);

I would still be interested if someone know's how to use simple html dom on css as there is nothing anywhere on the net. It may not even be possible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top