This article mainly and everyone to share the PHP curl to achieve mobile phone number attribution query function, hope to help everyone.
1, the code is as follows:
Index.html
Query_phone.php
<meta charset= "Utf-8" ><?php header ("Content-type:text/html,charset=utf8"); Include (' simple_html_dom.php '); function query ($phone = ') {$url = ' http://www.ip138.com:8080/search.asp?action=mobile&mobile= '. $phone; $ch = Curl_init (); $timeout = 5; curl_setopt ($ch, Curlopt_url, $url); 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); curl_setopt ($ch, Curlopt_referer, ' Http://www.cltt.org/studentscore '); $contents = curl_exec ($ch); $contents = mb_convert_encoding ($contents, ' utf-8 ', ' gbk,gb18030,gb2312 '); Curl_close ($ch); return $contents; } function Simple ($phone = ") {$contents = query ($phone); $html = new Simple_html_dom (); $html->load ($contents); $ARRMSG = Array ();foreach ($html->find (' table tbody tr TD ') as $m) {Array_push ($ARRMSG, $m->plaintext); } return $ARRMSG; } $ph =$_get["Phone"]; Var_dump (Simple ($ph));? >
simple_html_dom.php
Need to download PHP parsing HTML class library: simple_html_dom.php
2. Effect