PHP some practical self-made methods

Source: Internet
Author: User

Tags: pos style create ADE URL UCS LSE Validate output

JSON garbled to Chinese

function decodeunicode ($str) {  returnpreg_replace_callback('/\\ \\u ([0-9a-f]{4})/I ',    create_function      (' $matches ',      ' return mb_convert_encoding ( Pack ("h*", $matches [1]), "UTF-8", "ucs-2be"); '     ),    $str);}

Curl Crawler

function_grab ($curl,$postInfo= ",$cookie= ",$referer= ",$userAgent= ' '){     $ch=Curl_init (); curl_setopt ($ch, Curlopt_url,$curl); //No output headercurl_setopt ($ch, Curlopt_header, 0); //returns the information obtained as a string without directly outputtingcurl_setopt ($ch, Curlopt_returntransfer, 1); //if it is an HTTPS link, the certificate is not verified     if(Preg_match('/https/i ',$curl) {curl_setopt ($ch, Curlopt_ssl_verifypeer,false); }     //POST     if($postInfo) {curl_setopt ($ch, curlopt_post,1); curl_setopt ($ch, Curlopt_postfields,$postInfo); }     //Add a cookie     if($cookie) {curl_setopt ($ch, Curlopt_cookie,$cookie); }     //Analog Route     if($referer) {curl_setopt ($ch, Curlopt_referer,$referer); }     //Simulation Environment     if($userAgent) {curl_setopt ($ch, Curlopt_useragent,$userAgent); }     //Execution     $content= Curl_exec ($ch); //Error Handling     if($content===false) {         return"Network request error:". Curl_error ($ch); Exit(); }       return $content;}

PHP some practical self-made methods

Related Article

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: and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: