Use Baidu to correct incorrect words or characters-PHP source code

Source: Internet
Author: User
Tags preg
Use Baidu to correct incorrect words or characters
// Simulate request post 2015-09-26function post ($ url, $ data, $ array = '0') {if ($ array = '0 ') // The browser information is null {$ array = array ("Referer: {$ url}", 'user-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) appleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/100');} $ ch = curl_init ($ url); curl_setopt ($ ch, CURLOPT_HEADER, 0 ); // Two lines dedicated to https // curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, FALSE); // curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt ($ ch, expires, 1); curl_setopt ($ ch, CURLOPT_TIMEOUT, 3); // Number of timeout seconds curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ data ); curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ array); // line feed for sending the analog information array $ post_array = array ('Accept-Encoding: gzip '); $ curlsc = curl_exec ($ ch); // save as the variable curl_close ($ ch); Return $ curlsc;} // simulate the request get 2015-09-26function get ($ url, $ array = '0') {if ($ array = '0') // The browser information is null {$ array = array ('User-Agent: mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/100', "Referer: {$ url }",);} $ ch = curl_init ($ url); // initialize curl_setopt ($ ch, CURLOPT_HEADER, 0); // no header part is returned // curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1 ); // curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ array) is reported when automatic redirect is used; // A new line is required for sending the simulation information array $ post_array = array ('Accept-Encoding: gzip '); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); // returns a string instead of directly outputting the source code curl_setopt ($ ch, CURLOPT_TIMEOUT, 3 ); // timeout seconds $ curl = curl_exec ($ ch); curl_close ($ ch); return $ curl;} // use Baidu detection to correct the character $ url =" http://m.baidu.com/s?word= {$ M} "; $ url = get ($ url); if (strstr ($ url, 'correct-Q ')) {$ preg = '# class = "correct-q"> (. *) # iUs '; // # iUs'; preg_match_all ($ preg, $ url, $ zz); $ a = $ zz [1] [0]; echo "are you looking for {$ a} \ n? enter the correct name again. ";}Else {echo 'None ';}

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.