<?php /** * The basic usage of this library. * If you're a beginner and 'Lloyd\Shorten\Create' scares you, don't let it! */ // Include the library include "googl.class.php"; // The URL we want to shorten $url = "https://github.com/lloydaaa"; // New Googl class $googl = new Googl('YOUR API KEY', $url); // Display our generated shortened link echo $googl->generate();
} else { println('Passed!'); } } function assert_url($is) { if (!preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $is)) { exit(1); } else { println('Passed!'); } } function println($text) { echo $text . "\n"; } require 'Googl.class.php'; # # IMPORTANT: Please add your API key to make the tests work # $googl = new Googl('YOUR_API_KEY'); println('#1 - Assert that shortening http://www.google.ch results in an URL'); assert_url($googl->shorten('http://www.google.ch')); println('#2 - Assert that expanding http://goo.gl/KSggQ resolves to http://www.google.com/'); assert_equals($googl->expand('http://goo.gl/KSggQ'), 'http://www.google.com/'); println('#3 - Assert that shortening https://www.facebook.com results in an URL'); assert_url($googl->shorten('https://www.facebook.com')); println('#4 - Assert that expanding http://goo.gl/wCWWd resolves to http://www.php.net/'); assert_equals($googl->expand('http://goo.gl/wCWWd'), 'http://www.php.net/'); # If this point is reached, all tests have passed println('All tests have successfully passed!');
<?php // http://localhost:8080/php-sms-twilio/index.php?printcode=DF56TR78UJ require_once 'GooShortUrl.php'; $longUrl = "http://wiadomosci.onet.pl/swiat/bialorus-rosnie-poparcie-dla-lukaszenki-i-chec-zjednoczenia-z-rosja/z1nch"; $goo = new Googl(); $r = $goo->setShortUrl($longUrl); var_dump($r); echo $r['id'];
<?php /** * This is the basic usage of the Googl URL generator * If you're a beginner and the 'Lloyd\Shorten\Create' scares you, don't let it! * It's extremely easy to use **/ // Include the library require_once "googl.class.php"; // New Googl class $Googl = new Googl(['api_key' => 'YOUR_GOOGLE_API_KEY']); // Display our generated shortened link echo $Googl->shorten("https://github.com/lloydaaa"); // Shorten several links, put into a one-dimentional array // Output - ['http://goo.gl/GjcEix', 'http://goo.gl/FxcErx', 'http://goo.gl/rjFxiI'] $links = $Googl->shorten(["https://github.com/lloydaaa", "https://twitter.com/lloydaaa", "https://google.com"]);
} function println($text) { echo $text . "\n"; } require 'Googl.class.php'; # # IMPORTANT: Please add your API key to make the tests work # $googl = new Googl('YOUR_API_KEY'); println('#1 - Assert that shortening http://www.google.ch results in an URL'); assert_url($googl->shorten('http://www.google.ch')); println('#2 - Assert that expanding http://goo.gl/KSggQ resolves to http://www.google.com/'); assert_equals($googl->expand('http://goo.gl/KSggQ'), 'http://www.google.com/'); println('#3 - Assert that shortening https://www.facebook.com results in an URL'); assert_url($googl->shorten('https://www.facebook.com')); println('#4 - Assert that expanding http://goo.gl/wCWWd resolves to http://www.php.net/'); assert_equals($googl->expand('http://goo.gl/wCWWd'), 'http://www.php.net/'); unset($googl); $googl = new Googl('BAD_KEY'); println('---Assert with Bad key---'); println('#1 - Assert that shortening http://www.google.ch results in an URL'); assert_url($googl->shorten('http://www.google.ch', true)); println('#2 - Assert that expanding http://goo.gl/KSggQ resolves to http://www.google.com/'); assert_equals($googl->expand('http://goo.gl/KSggQ', true), 'http://goo.gl/KSggQ'); println('#3 - Assert that shortening https://www.facebook.com results in an URL'); assert_url($googl->shorten('https://www.facebook.com', true)); println('#4 - Assert that expanding http://goo.gl/wCWWd resolves to http://www.php.net/'); assert_equals($googl->expand('http://goo.gl/wCWWd', true), 'http://goo.gl/wCWWd'); # If this point is reached, all tests have passed println('All tests have successfully passed!');