PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Kevinralph M Tenorio   PHP Short URL API   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example usage
Class: PHP Short URL API
Create short URLs and expand them using Google API
Author: By
Last change: Typo key.
Date: 5 years ago
Size: 782 bytes


Class file image Download

     * @param string $longUrl
     * @param string|null $api
     * @return string|bool
function googl_url($longUrl, $api = null)
$instance = new GoogleURLAPI($api);

        if (
$response = $instance->shorten($longUrl)) {
            return isset(
$response['id']) ? $response['id'] : $longUrl;

$shorten = googl_url('');

// Other Example Usage:

$googlurl = new GoogleURLAPI('MY_GOOGLE_URL_SHORTER_API_KEY');
$short = $googlurl->shorten('');
$long = $googlurl->expand($short['id']);
var_dump([$short, $long]);