html-php how to get the hyperlinks on the page and fulfill the address?

Source: Internet
Author: User
Keywords Php html
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

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.