} 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 /** * 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"]);