This library for simple to take short url. Usind Google Shortener API.
Require this package with Composer.
composer require monster3d/php-url-shortener
Or add your dependencies to composer.json file
"require": {
"monster3d/php-url-shortener": "*"
}
<?php
//include composer
require __DIR__ . '/vendor/autoload.php';
use Monster3D\Shortener\Short;
//Set google api key
Short::setGoogleAPIKey('YOUR-GOOGLE-API-KEY');
$result = Short::link('http://mylongurl.ru/');
print_r($result);
in the var: $result will be stdClass object.
stdClass object
(
[kind] => urlshortener#url
[id] => https://goo.gl/VQ5T
[longUrl] => http://mylongurl.ru/
)