Simple code for php to read html and extract strings

Source: Internet
Author: User
Generally, php collection code can be used. here is a simple implementation code. The code is as follows:


$ Title = 'foot home ';
$ Hello = 'jb51. net! ';
$ File = file_get_contents ('http: // www.baidu.com ');
$ File = iconv ("gbk // IGNORE", "UTF-8", $ file );
// Echo $ file;
Echo strpos ($ file ,''); <BR> echo substr ($ file, strpos ($ file,' <title> ') + 7, strpos ($ file ,''-Strpos ($ file ,'') + 7 ));
$ File = str_replace (array ('Baidu review ',' {hello} '), array ($ title, $ hello), $ file );
?>


The following is the program code of the thieves used by Yuhai. For more information, see. The script home provides a variety of thieves.

The code is as follows:


Function _ url ($ Date ){
$ Ch = curl_init ();
$ Timeout = 5;
Curl_setopt ($ ch, CURLOPT_URL, "$ Date ");
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1 )");
Curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, $ timeout );
$ Contents = curl_exec ($ ch );
Curl_close ($ ch );
Return $ contents;
}
$ Url = "http://www.jb51.net ";
$ Contents. = _ url ($ url );
Echo $ contents; // Output Content
?>

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.