Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function googl($longUrl)
- {
- $post = json_encode(array('longUrl' => $longUrl));
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url');
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
- $result = json_decode(curl_exec($ch));
- curl_close($ch);
- if(isset($result->id)) return $result->id;
- return false;
- }
- echo googl('http://www.google.com');
- ?>
Add Comment
Please, Sign In to add comment