问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/4419528/change-relative-path-to-full-in-css