Common PHP methods

Source: Internet
Author: User

/** 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

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.