PHP access to all Web page connection method (with demo source download), demo source Download _php Tutorial

Source: Internet
Author: User
Tags php regular expression

PHP access to all Web page connection method (with demo source download), demo source download

The example in this article describes how PHP obtains all connections to a Web page. Share to everyone for your reference, as follows:

function gethtml ($url, $charset = ' utf-8 ') {$curl = Curl_init ();  curl_setopt ($curl, Curlopt_httpheader, Array (' x-forwarded-for: ', ' client-ip: '));//IP  curl_setopt ($curl, Curlopt_url, $url);  curl_setopt ($curl, Curlopt_referer, ""); Route $user _agent = isset ($_server[' http_user_agent ')? $_server[' http_user_agent ': ' mozilla/5.0 (Windows NT 5.1) applewebkit/537.31 (khtml, like Gecko) chrome/26.0.1410.43 Sa  Fari/537.31 ';  curl_setopt ($curl, curlopt_useragent, $user _agent);  Simply return HTTP header//curl_setopt ($curl, Curlopt_header, 1);  Page content We do not need//curl_setopt ($curl, curlopt_nobody, 1);  Returns the result instead of outputting it curl_setopt ($curl, Curlopt_returntransfer, 1);  $html = curl_exec ($curl);  $info = Curl_getinfo ($curl);  echo Var_dump ($info); if ($html = = = False) {//echo "CURL Error:".    Curl_error ($ch);  Return ';  } curl_close ($curl);  if ($charset! = ' Utf-8 ') {$html = Iconv ($charset, "UTF-8", $html); } return $html;} Header ("Content-type:text/html Charset=utf-8 "), include (' simple_html_dom.php ');//To open extension=php_mbstring.dll//$url = ' Wd=kaka '; $url = ''; $str _html = gethtml ($url, ' GBK '); $html = str_get_html ($str _html); $links = $html-&  Gt;find (' a '); foreach ($links as $link) {$txt = Trim ($link->plaintext); Echo $link->href. ' ['. $txt. ']
';} $html = null;

Full instance code click here to download this site.

More interested in PHP related content readers can view this site: "PHP Network Programming Skills Summary", "PHP Basic Grammar Introductory Tutorial", "PHP operation Office Document Skills Summary (including word,excel,access,ppt)", " PHP Date and Time usage summary, PHP Object-oriented Programming primer, PHP string usage Summary, PHP+MYSQL Database Operations Primer, and PHP Common database operations Tips Summary

I hope this article is helpful to you in PHP programming.

Articles you may be interested in:

    • How PHP gets all the links on a Web page
    • PHP Regular expression extract Web hyperlink URL function
    • About PHP functions for getting home page and site links in WordPress
    • The use of PHP functions to get page links and headings in WordPress
    • PHP gets the hyperlink text content regular expression (five methods)
    • PHP Regular Expressions get all the links to content
    • How to get the real address and response header information of a short link jump after PHP
    • PHP Self-write function code get keyword go hyperlink true techarticle PHP access to all the Web page connection method (with the demo source download), demo Source Download This example describes how PHP gets all the connections to the Web. Share to everyone for your reference, as follows ...

  • Related Article

    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: 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.