/** HTTP Encapsulation Network request method*/ /** Get Method*/ functionGet$url,$param=Array()){ if(!Is_array($param)){ Throw New Exception("parameter must be an array"); } $p= ' '; foreach($param as $key=$value){ $p=$p.$key.‘ = '.$value.‘ & '; } if(Preg_match(‘/\? [\d\d]+/',$url)){//matched? C $p= ' & '.$p; }Else if(Preg_match('/\?$/',$url)){//matched? $ $p=$p; }Else{ $p= '? '.$p; } $p=Preg_replace('/&$/', ',$p); $url=$url.$p; //echo $url; $httph=curl_init ($url); curl_setopt ($httph, Curlopt_ssl_verifypeer, 0); curl_setopt ($httph, Curlopt_ssl_verifyhost, 1); curl_setopt ($httph, curlopt_returntransfer,1); curl_setopt ($httph, Curlopt_useragent, "mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) "); curl_setopt ($httph, curlopt_returntransfer,1); curl_setopt ($httph, curlopt_header,1); $rst=curl_exec ($httph); Curl_close ($httph); return $rst; } /** Post Method*/ functionPost$url,$param=Array()){ if(!Is_array($param)){ Throw New Exception("parameter must be an array"); } $httph=curl_init ($url); curl_setopt ($httph, Curlopt_ssl_verifypeer, 0); curl_setopt ($httph, Curlopt_ssl_verifyhost, 1); curl_setopt ($httph, curlopt_returntransfer,1); curl_setopt ($httph, Curlopt_useragent, "mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) "); curl_setopt ($httph, Curlopt_post, 1);//set to post modecurl_setopt ($httph, Curlopt_postfields,$param); curl_setopt ($httph, curlopt_returntransfer,1); curl_setopt ($httph, curlopt_header,1); $rst=curl_exec ($httph); Curl_close ($httph); return $rst; } /** * PHP Send JSON Object data * * @param $url Request URL * @param $jsonStr the JSON string sent * @return array*/ functionHttp_post_json ($url,$jsonStr) { $ch=Curl_init (); curl_setopt ($ch, Curlopt_post, 1); curl_setopt ($ch, Curlopt_url,$url); curl_setopt ($ch, Curlopt_postfields,$jsonStr); curl_setopt ($ch, Curlopt_returntransfer, 1); curl_setopt ($ch, Curlopt_httpheader,Array( ' Content-type:application/json; Charset=utf-8 ', ' content-length: '.strlen($jsonStr) ) ); $response= Curl_exec ($ch); $httpCode= Curl_getinfo ($ch,Curlinfo_http_code); return Array($httpCode,$response); } /** * php Get directory tree * * @param [string] $path [directory path] * @return [array] [directory structure array]*/ functionDirTree ($path) { $handle=Opendir($path); $itemArray=Array(); while(false!== ($file=Readdir($handle))) { if(($file= = '. ') | | ($file= = ' ... ')){ }ElseIf(Is_dir($path.$file)) { Try { $dirtmparr=dirtree ($path.$file.‘ /‘); } Catch(Exception $e) { $dirtmparr=NULL; }; $itemArray[$file]=$dirtmparr; }Else{ Array_push($itemArray,$file); } } return $itemArray;}
Not much to say, there are instructions
Common PHP methods