Shortening URL with and PHP

// This is the URL you want to shorten
$longUrl = '';

// Get API key from :
$apiKey = 'MyAPIKey';

$postData = array('longUrl' => $longUrl, 'key' => $apiKey);
$jsonData = json_encode($postData);

$curlObj = curl_init();

curl_setopt($curlObj, CURLOPT_URL, '');
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curlObj, CURLOPT_HEADER, 0);
curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
curl_setopt($curlObj, CURLOPT_POST, 1);
curl_setopt($curlObj, CURLOPT_POSTFIELDS, $jsonData);

$response = curl_exec($curlObj);

// Change the response json string to object
$json = json_decode($response);


echo 'Shortened URL is: '.$json->id;

Shopping di DDShop.Online:
- gadget murah
- barang rare
- F&B halal Muslim
Lawat DDShop.Online dan alami pengalaman BARU!

Leave a Reply

Your email address will not be published. Required fields are marked *