使用DOMDocument在html文档中将相对URL更改为绝对

时间:2022-10-20 15:38:45

I am using curl to get some html pages in strings, but I have a problem when i display it , it doesn't show the images nor the css ,let say the data have this want to get modified to thanks! I want it to modify the whole html page ...

我使用curl来获取字符串中的一些html页面,但是当我显示它时,我有一个问题,它没有显示图像也没有显示css,让我们说这个数据有想要修改为谢谢!我希望它能修改整个html页面......

2 个解决方案

#1


1  

You can use wget with the -k option. Or just see the answers here.

您可以将wget与-k选项一起使用。或者只是在这里看到答案。

#2


1  

Your problem is that links to images and stylesheets are relative instead of absolute, so your browser doesn't know the real origin of the page when displaying it. A quick fix would be to add

您的问题是图像和样式表的链接是相对的而不是绝对的,因此您的浏览器在显示时不知道页面的真实来源。快速解决方法是添加

<base href="http://domain.com" /> 

(with the real originating domain) in the head of your page prior to displaying it.

(在真正的原始域中)在显示之前在页面的头部。

#1


1  

You can use wget with the -k option. Or just see the answers here.

您可以将wget与-k选项一起使用。或者只是在这里看到答案。

#2


1  

Your problem is that links to images and stylesheets are relative instead of absolute, so your browser doesn't know the real origin of the page when displaying it. A quick fix would be to add

您的问题是图像和样式表的链接是相对的而不是绝对的,因此您的浏览器在显示时不知道页面的真实来源。快速解决方法是添加

<base href="http://domain.com" /> 

(with the real originating domain) in the head of your page prior to displaying it.

(在真正的原始域中)在显示之前在页面的头部。