Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created October 31, 2019 01:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/798493bb52b8c69626d2ff3040de6c51 to your computer and use it in GitHub Desktop.
Save parzibyte/798493bb52b8c69626d2ff3040de6c51 to your computer and use it in GitHub Desktop.
<?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