在css中将相对路径更改为完整 [英] Change relative path to full in css
问题描述
我使用简单的html dom从网站提取数据和pharse它。然而,我不能将样式标签中的一条实际路径更改为完整路径。我已经尝试过很多组合。
我在这里找到一个帖子,使用简单的html dom的PEAR脚本,它在除了下面的所有链接上都有效。
require_once'includes / URL2.php';
$ uri = new Net_URL2('http://www.stormcinemas.ie'); //资源的URI
$ baseURI = $ uri;
foreach($ htmlcss-> find('background [url]')as $ elem){
$ elem-> url = $ baseURI-& > 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-& - > action) - > __ toString();
}
style.css
< style>
div.spriteImgSmall {background:url(/images/css_sprites/film_sprites/smallimages_sprite.jpg); }
< / style>感谢解决方案 div> 解决方案是在这里提供,但不幸的是被删除。再次感谢,它实际上解决了我的问题。
这是未来的参考。
$ htmlcss = preg_replace('/ url\(\s * [\']?\ /?(。+?)[\']?\s * \ )/ i','url('。
$ baseURI。'/ $ 1)',$ htmlcss);
如果有人知道如何在css上使用简单的html dom,网络上。这甚至不可能。
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
解决方案 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.
这篇关于在css中将相对路径更改为完整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文