PHP code example of waimao / shorturl-service

1. Go to this page and download the library: Download waimao/shorturl-service 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/ */

    

waimao / shorturl-service example snippets




//Create the short url. Optionally pass the $apiKey credentials
$googl = new \Waimao\Service\ShortLink\Google($apiKey);
echo $url = $googl->shorten($longUrl);

//Expand a short URL into the original URL. Optionally pass the $apiKey credentials
$googl = new \Waimao\Service\ShortLink\Google($apiKey);
echo $url = $googl->expand($shortUrl);

//Get all data, including statistics for a shortened URL
$googl = new \Waimao\Service\ShortLink\Google($apiKey);
$array = $googl->stats($shortUrl);



//Create the short url.
$bitly = new \Waimao\Service\ShortLink\Bitly($user,$pass);
echo $url = $bitly->shorten($longUrl);

//Expand a short URL into the original URL.
$bitly = new \Waimao\Service\ShortLink\Bitly($user,$pass);
echo $url = $bitly->expand($shortUrl);