PHP code example of bingher / short-url
1. Go to this page and download the library: Download bingher/short-url library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bingher / short-url example snippets
u = [
'driver'=>'baidu',
'app_key'=>'your token',
'validity' => '1-year', //有效期 永久:long-term,1年:1-year
];
$sina = [
'driver'=>'sina',
'app_key'=>'your appKey'
];
$surl = new \bingher\surl\Surl($sina);
/*create short url*/
$longUrl = 'http://www.2vm.net.cn';
var_dump('longUrl:');
var_dump($longUrl);
$shortUrl = $surl->create($longUrl);
if ($shortUrl === false) {
var_dump('create short url error:');
var_dump($surl->getError());
}
var_dump('shortUrl:');
var_dump($shortUrl);
/*query long url from short url*/
$checkLongUrl = $surl->query($shortUrl);
if ($checkLongUrl === false) {
var_dump('query short url error:');
var_dump($surl->getError());
}
var_dump('shortUrl:'.$shortUrl.' expand long url:');
var_dump($checkLongUrl);