


Sina short link generation and restoration short link tutorial
Short link, in layman's terms, is to convert a long URL into a short URL string through program calculation and other methods. Regarding Sina short links, we can use the Sina Weibo short link generator, which is a small tool that can generate t.cn short links. But what if we implement Sina short links ourselves? In this article, we will teach you how to use php to generate Sina short links and restore Sina short link classes.
<?php /* * 生成新浪的短链接或还原新浪短链接 * date 2017年11月22日 * author www.phpernote.com */ class SinaUrl{ //新浪APPKEY const APPKEY='31641035'; //CURL private static function CURLQueryString($url){ //设置附加HTTP头 $addHead=array("Content-type: application/json"); //初始化curl,当然,你也可以用fsockopen代替 $curl_obj=curl_init(); //设置网址 curl_setopt($curl_obj,CURLOPT_URL,$url); //附加Head内容 curl_setopt($curl_obj,CURLOPT_HTTPHEADER,$addHead); //是否输出返回头信息 curl_setopt($curl_obj,CURLOPT_HEADER,0); //将curl_exec的结果返回 curl_setopt($curl_obj,CURLOPT_RETURNTRANSFER,1); //设置超时时间 curl_setopt($curl_obj,CURLOPT_TIMEOUT,8); //执行 $result=curl_exec($curl_obj); //关闭curl回话 curl_close($curl_obj); return $result; } //处理返回结果 private static function doWithResult($result,$field){ $result=json_decode($result,true); return isset($result[0][$field])?$result[0][$field]:''; } //获取短链接 public static function getShort($url){ $url='http://api.t.sina.com.cn/short_url/shorten.json?source='.self::APPKEY.'&url_long='.$url; $result=self::CURLQueryString($url); return self::doWithResult($result,'url_short'); } //获取长链接 public static function getLong($url){ $url='http://api.t.sina.com.cn/short_url/expand.json?source='.self::APPKEY.'&url_short='.$url; $result=self::CURLQueryString($url); return self::doWithResult($result,'url_long'); } } //使用示例,如下: $result=SinaUrl::getShort('http://www.phpernote.com/'); echo $result; //http://t.cn/zYzBqAU $result=SinaUrl::getLong('http://t.cn/zYzBqAU'); echo $result; //http://www.phpernote.com/
The above is a summary of the classes (methods) for generating Sina short links and restoring Sina short links. I hope it can help everyone.
Related recommendations:
PHP implements URL long connection generation short link operation
Link php short link algorithm collection and analysis
Weibo short link algorithm PHP version_PHP tutorial
The above is the detailed content of Sina short link generation and restoration short link tutorial. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Magnet link is a link method for downloading resources, which is more convenient and efficient than traditional download methods. Magnet links allow you to download resources in a peer-to-peer manner without relying on an intermediary server. This article will introduce how to use magnet links and what to pay attention to. 1. What is a magnet link? A magnet link is a download method based on the P2P (Peer-to-Peer) protocol. Through magnet links, users can directly connect to the publisher of the resource to complete resource sharing and downloading. Compared with traditional downloading methods, magnetic

Recently, many users have been asking the editor, how to download links starting with 115://? If you want to download links starting with 115://, you need to use the 115 browser. After you download the 115 browser, let's take a look at the download tutorial compiled by the editor below. Introduction to how to download links starting with 115:// 1. Log in to 115.com, download and install the 115 browser. 2. Enter: chrome://extensions/ in the 115 browser address bar, enter the extension center, search for Tampermonkey, and install the corresponding plug-in. 3. Enter in the address bar of 115 browser: Grease Monkey Script: https://greasyfork.org/en/

As part of the WeChat ecosystem, WeChat video accounts have gradually become an important promotion tool for content creators and merchants. Getting links to video accounts on this platform is crucial for sharing and disseminating content. The following will introduce in detail how to obtain the WeChat video account link and how to add product links to the video account to improve the dissemination effect of the content. 1. How to get the WeChat video account link? After posting a video on your WeChat video account, the system will automatically create a video link. Authors can copy the link after publishing to facilitate sharing and dissemination. After logging in to your WeChat video account, you can browse the homepage of your video account. On the home page, each video is accompanied by a corresponding link so you can copy or share it directly. 3. Search video account: Enter the video account name in the WeChat search box

Link AppleNotes on iPhone using the Add Link feature. Notes: You can only create links between Apple Notes on iPhone if you have iOS17 installed. Open the Notes app on your iPhone. Now, open the note where you want to add the link. You can also choose to create a new note. Click anywhere on the screen. This will show you a menu. Click the arrow on the right to see the "Add link" option. click it. Now you can type the name of the note or the web page URL. Then, click Done in the upper right corner and the added link will appear in the note. If you want to add a link to a word, just double-click the word to select it, select "Add Link" and press

With the popularity of short video platforms, more and more creators are beginning to use video accounts to create and promote content. Video accounts can not only showcase personal talents, but also realize commercial monetization through product links. However, to add a link to a video account, certain conditions must be met. 1. What are the requirements for a video link? Video account authentication is a prerequisite for adding links to your video account. Currently, major short video platforms such as Douyin and Kuaishou provide certification services, which mainly include two types: personal certification and institutional certification. Personal certification requires the submission of real identity information, while institutional certification requires the provision of certification materials from relevant companies or organizations. After completing the authentication, users can add links to their video accounts to enhance the credibility and authority of their accounts. One of the video link

How to Stop Outlook from Opening Links in Edge Before proceeding, make sure your preferred browser is set as the default browser in Windows. This ensures that the Outlook link opens in the desired browser. To check and set your default browser: For Windows 10: Click the Start menu and select Settings Go to Apps and then Default Apps Look for "Web Browser" at the bottom of the list of default apps ” If your preferred browser is listed, you’re all set. If Microsoft Edge is listed, click on it and select your preferred browser from the list. If prompted, click Switch Anyway. Fix Edge issues

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

iFlytek has upgraded the meeting minutes function, which can directly convert spoken expressions into written drafts, and AI can summarize meeting minutes based on recordings. AI can help you complete the writing of meeting minutes. On August 31, the iFlytek web version was upgraded, adding a real-time recording function on the PC side, which can use artificial intelligence to intelligently generate meeting minutes. The launch of this function will greatly improve the efficiency of users in organizing content and following up on key work items after meetings. For people who often attend meetings, this function is undoubtedly a very practical tool that can save a lot of time and energy. The application scenario of this function is mainly to convert recordings on the PC to text and automatically generate meeting minutes, aiming to provide users with the best quality. Products with excellent services and the most advanced technology to quickly improve office efficiency
