在css中将相对路径更改为完整路径

发布于 2024-10-07 01:24:19 字数 1048 浏览 6 评论 0原文

我正在使用简单的 html dom 从网站中提取数据并对其进行分段。然而,我无法将样式标签中的相对路径之一更改为完整路径。我尝试过很多组合。

我在这里找到了一篇文章,使用带有简单 html dom 的 PEAR 脚本,它适用于除下面之外的所有链接。

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>

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白色秋天 2024-10-14 01:24:19

此处提供了解决方案,但不幸的是被删除了。再次感谢,它确实解决了我的问题。

这是供将来参考的。

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

如果有人知道如何在 css 上使用简单的 html dom,我仍然会感兴趣,因为网络上没有任何东西。这甚至可能是不可能的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文