Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从锚href获取完全限定的URL?_Php_Html_Url_Anchor_Href - Fatal编程技术网

Php 如何从锚href获取完全限定的URL?

Php 如何从锚href获取完全限定的URL?,php,html,url,anchor,href,Php,Html,Url,Anchor,Href,我正在用php编写一个网络爬虫。给定当前URL和指向绝对URL、相对URL和根URL的链接数组,如何确定每个链接的完全限定URL 例如,假设我正在抓取URL: http://www.example.com/path/to/my/file.html 该网页包含的链接数组为: array( 'http://www.some-other-domain.com/', '../../', '/search', ); 我如何确定每个链接的完全限定URL?我在本例中寻找的结果分别是

我正在用php编写一个网络爬虫。给定当前URL和指向绝对URL、相对URL和根URL的链接数组,如何确定每个链接的完全限定URL

例如,假设我正在抓取URL:

http://www.example.com/path/to/my/file.html
该网页包含的链接数组为:

array(
    'http://www.some-other-domain.com/',
    '../../',
    '/search',
);
我如何确定每个链接的完全限定URL?我在本例中寻找的结果分别是:

http://www.some-other-domain.com/
http://www.example.com/path/
http://www.example.com/search/

我认为最简单的方法是使用这样的库:

链接中的示例:

url_to_absolute('http://www.example.com/sitemap.html', 'aboutus.html');
解析为
http://www.example.com/aboutus.html


解析为
http://www.example.com/images/somephoto.jpg

别忘了你可能还需要考虑其他一些东西——比如HTML文档中的f.e.a
。这并不像你想象的那么简单(从你的问题来看,你似乎一开始就没有那么认真地思考过……)
url_to_absolute('http://www.example.com/content/sitemap.html', '../images/somephoto.jpg');