Php implements Sina short link call API code

Source: Internet
Author: User
I have previously written an article about anti-leeching in images. I have used sina short connections for my own webpage, which is convenient for short connections, the address is too long. the source code is shared below, which has comments and is not original. the code is as follows :? PhpSina... I have previously written an article about anti-leeching in images. I have used sina short connections for my own webpage, which is convenient for short connections, if the address is too long, the source code is shared below, which has annotations and is not original. the code is as follows:

 Error) |! Isset ($ json [0]-> url_short) | $ json [0]-> url_short = '') return false; else return $ json [0]-> url_short;} // Obtain the long URL based on the short url. this function reuse a lot of codes in sinaShortenUrl to facilitate your reading and comparing, you can merge two function sinaExpandUrl ($ short_url) {// concatenate the request address. you can view $ url = 'http: // api.t.sina.com.cn/short_url/expand.json in the official documentation? Source = '. SINA_APPKEY. '& url_short = '. $ short_url; // get the request result $ result = curlQuery ($ url); // the following line of comment is used for debugging, you can remove the comment to see what is returned from sina // print_r ($ result); exit (); // parse json $ json = json_decode ($ result ); // if an exception occurs, false if (isset ($ json-> error) is returned. |! Isset ($ json [0]-> url_long) | $ json [0]-> url_long = '') return false; else return $ json [0]-> url_long;} // open-source phpfensi.com//the URL of the website to be scaled down =long long; // You can view it here, modify it to the URL you want to shorten or to get the post data or how to drop it. $ Url = filterUrl ($ url); $ short = sinaShortenUrl ($ url); $ ulong = sinaExpandUrl ($ short);?>

In this article, the appkey that has been attached to the short connection does not need to apply for the KEY by yourself. of course, if you need to use your own appkey, you can replace it by yourself. the usage depends on you, embedded into other programs for use? I don't care if I create a page that generates a short connection. I don't know how to use it. recently, it's relatively lazy.


Permanent link:

Reprint at will! Include the article address.

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.