PHP Code Basics

Source: Internet
Author: User
Tags urlencode

How to access Sina API

<?phpfunction Getweibodata () {$count = 15;//parameter source After you enter your grant number, "Https://api.weibo.com/2/statuses/home_ Timeline.json?source=123456789&count= ". $count." &page=1 "; Echo $url. ' <br/> '; $curl = Curl_init (); curl_setopt ($curl, Curlopt_url, $url);//Set whether to display header information 0 is not displayed, 1 is display  default to 0//curl_ Setopt ($curl, Curlopt_header, 0);//sets the curl parameter, which requires the result to be saved to a string or output to the screen. 0 is displayed on the screen, 1 is not displayed on the screen, the default is 0curl_setopt ($curl, Curlopt_ssl_verifypeer, false); curl_setopt ($curl, Curlopt_returntransfer, 1);//user name password to verify curl_setopt ($curl, Curlopt_userpwd, "Username:password"); $data = Curl_exec ($curl); Curl_close ($curl); $result = Json_decode ($data, true); Echo ' <pre> ';p rint_r ($result); Echo ' </pre> ';}? >

Get the size of a picture remotely

Usage echo remote_filesize ($url, $user = ', $PW = '); $url = "http://www.nowamagic.net/librarys/images/random/rand_11. JPG "; Echo remote_filesize ($url, $user =", $PW = "); function Remote_filesize ($uri, $user =", $PW = ") {//Start output Buffering Ob_start ();//Initialize curl with given URI $ch = Curl_init ($uri); Make sure we get the header curl_setopt ($ch, Curlopt_header, 1); Make it a HTTP HEAD request curl_setopt ($ch, curlopt_nobody, 1);  If Auth is needed, does it here if (!empty ($user) &&!empty ($PW)) {$headers = Array (' Authorization: Basic '.        Base64_encode ($user. ': ' $pw));    curl_setopt ($ch, Curlopt_httpheader, $headers);    } $okay = Curl_exec ($ch); Curl_close ($ch); Get the output buffer $head = ob_get_contents ();  Clean the output buffer and return to previous//Buffer settings Ob_end_clean (); Gets the numeric value from the Content-length//field in the HTTP header $regex = '/content-length:\s ([0-9].+?    ) \s/'; $couNT = Preg_match ($regex, $head, $matches); If there is a content-length field, its value//would now is in $matches [1] if (Isset ($matches [1])) {$si    Ze = $matches [1];    } else {$size = ' unknown ';    } $last _mb = round ($size/(1024*1024), 3), $last _kb = round ($size/1024,3); Return $last _kb. ' KB/'. $last _mb. ' MB ';}

Check to see if your phone is logged in and jump

$agent = Check_wap (), if ($agent) {header (' location:http://www.baidu.com '); exit;} If it is a cell phone, function Check_wap () {//Check whether it is a WAP proxy, high accuracy if (stristr ($_server[' Http_via '), "WAP") {return true;} Check whether the browser accepts Wml.elseif (Strpos (Strtoupper ($_server[' http_accept ')), "VND. Wap. WML ") > 0) {return true;   }   Check user_agent   elseif (Preg_match ('/(blackberry|configuration\/cldc|hp |hp-|htc |htc_|htc-|iemobile|kindle| Midp|mmp|motorola|mobile|nokia|opera Mini|opera | googlebot-mobile| yahooseeker\/m1a1-r2d2|android|iphone|ipod|mobi|palm|palmos|pocket|portalmmm|ppc;|smartphone|sonyericsson|sqh| Spv|symbian|treo|up.browser|up.link|vodafone|windows ce|xda |xda_)/I ', $_server[' http_user_agent ']) {return true;} Else{return false;   }}

4 function UrlEncode to escape encoding when the URL is Chinese

  

<?php  //gb2312 's encode  echo urlencode ("Chinese-_."). " \ n "; %d6%d0%ce%c4-_.+  Echo UrlDecode ("%d6%d0%ce%c4-_."). " \ n "; Chinese-_.  Echo Rawurlencode ("Chinese-_."). " \ n "; %d6%d0%ce%c4-_.%20  Echo Rawurldecode ("%d6%d0%ce%c4-_."). " \ n "; Chinese-_.  ? >  

  

PHP Code Basics

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.