Curl gets a Web site parsing where a tag will be linked, some will be http://So complete, and some will be/about,. /about relative, there are some #,javascript and so on, how to match the links are all completed as a complete link (domain name plus relative), anchor and JS excluded?
Reply content:
Curl gets a Web site parsing where a tag will be linked, some will be http://So complete, and some will be/about,. /about relative, there are some #,javascript and so on, how to match the links are all completed as a complete link (domain name plus relative), anchor and JS excluded?
Just write a method to calculate it on the line. For example, request http://example.com/qa/list.php, where the host address is http://example.com and the directory address is http://example.com/qa/
If the address is HTTP (s)://begins with the full address
If the address is/starts, such as/aboutus, the full address is the host address + the address, i.e. Http://example.com/aboutus
If the address is a different beginning, such as: /aboutus, the full address is the directory address + the address, which is http://example.com/qa/../aboutus
If you think. /It's an eyesore, you can organize it yourself, each. /Offset Primary parent directory, become Http://example.com/aboutus
/** * 返回当前请求的完整URL * * @return string */function current_url(){ $host = $_SERVER['HTTP_HOST']; $uri = $_SERVER['REQUEST_URI']; return (is_https() ? 'https://' : 'http://') . $host . $uri;}
Well, it's the wrong question.
Questions about dealing with relative paths can be found in one of the articles I wrote earlier: http://blog.icewingcc.com/php-conv-addr-re-ab-2.html