Created
October 31, 2019 01:04
-
-
Save parzibyte/798493bb52b8c69626d2ff3040de6c51 to your computer and use it in GitHub Desktop.
Shorten ouo.io with PHP | https://parzibyte.me/blog/2018/08/03/api-de-ouo-con-php-acortar-enlaces/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function ouo_io($claveApi, $enlace){ | |
//Petición GET | |
$acortado = @file_get_contents( | |
"http://ouo.io/api/" | |
. urlencode($claveApi) | |
. "?s=" | |
. urlencode($enlace)); | |
// Comprobar si lo que obtuvimo | |
// es un enlace válido utilizando una | |
// expresión regular | |
if (preg_match('/^http:\/\/ouo\.io\/\w+$/', $acortado) !== 1) | |
throw new Exception("Enlace inesperado al acortar con ouo.io: " . $acortado); | |
return $acortado; | |
} | |
// Ejemplo de uso | |
$claveApi = "TU_CLAVE_API_AQUÍ"; | |
$enlace = "https://parzibyte.me/blog"; | |
echo ouo_io($claveApi, $enlace); //Salida: algo como http://ouo.io/D5UZXp | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment