<?php
 
 
    /**
 
     * @param string        $longUrl
 
     * @param string|null $api
 
     *
 
     * @return string|bool
 
     */
 
    function googl_url($longUrl, $api = null)
 
    {
 
        $api = $api ?? 'MY_GOOGLE_URL_SHORTER_API_KEY';
 
        $instance = new GoogleURLAPI($api);
 
 
        if ($response = $instance->shorten($longUrl)) {
 
            return isset($response['id']) ? $response['id'] : $longUrl;
 
        }
 
    }
 
 
    $shorten = googl_url('https://my.domain.com/some-very-long-url/?url=is_very_long');
 
 
    // Other Example Usage:
 
 
    $googlurl = new GoogleURLAPI('MY_GOOGLE_URL_SHORTER_API_KEY');
 
    $short = $googlurl->shorten('https://mylongdomain.com/long-url');
 
    $long = $googlurl->expand($short['id']);
 
    var_dump([$short, $long]);
 
 
 
 |