Instantly share code, notes, and snippets.

Embed
What would you like to do?
emoji.xyz URL shortener (I use ;smoji)
#!/usr/bin/php
<?php
// Request: Local emoji-web (http://emoji.xyz/shorten)
$ch = curl_init("http://emoji.xyz/shorten");
curl_setopt($ch, CURLOPT_POST, TRUE);
// Headers
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
));
// Body
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"url\":\"%clipboard\"}");
// Send synchronously
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
// Failure
if ($result === FALSE)
{
echo "cURL Error: " . curl_error($ch);
}
// Success
else
{
//echo "Request completed: " . $result;
$result = json_decode($result);
echo $result->{'url'};
}
curl_close($ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment