/ Published in: PHP
Expand |
Embed | Plain Text
// pass the url you want to shorten in $url when calling the fucntion // second arugument return the qr code url of the shortened goo.gl url // getgool("http://www.thisisthelongurltoshorten.com", TRUE); function getgoogl($url, $qr=NULL){ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, 'http://goo.gl/api/shorten'); curl_setopt($ch, CURLOPT_POST, TRUE); $results = curl_exec($ch); $headerInfo = curl_getinfo($ch); curl_close($ch); if ($headerInfo['http_code'] === 201){ // HTTP Code 201 = Created $results = json_decode($results); return $results->short_url.$qr; } return FALSE; } return FALSE; } return FALSE; }
You need to login to post a comment.
