Shortened Google, bit. ly, is. gd, and x. co URLs
1.[Code][PHP] code
11) // get the longurl. if the length is short, it is useless to compress {$ url = $ _ GET ["u"]; if (filter_var ($ url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED) {$ longurl = urlencode ($ url); // begin bitly $ login = "helong"; // bitly login name $ apikey = "success "; // bitly apikey https://www.php1.cn/javasformat= "txt"; // bitly api format $ bitly = 'http: // api. bit. ly/v3/shorten? LongUrl = '. $ longurl. '& login = '. $ login. '& apiKey = '. $ apikey. '& format = '. $ format; $ bitly = file_get_contents ($ bitly); $ bitly = trim ($ bitly); echo $ bitly; echo"
"; // Begin isgd $ isgd = 'http: // is. gd/create. php? Format = simple & url = '. $ longurl; $ isgd = file_get_contents ($ isgd); $ isgd = trim ($ isgd); echo $ isgd; echo"
"; // Begin googleinclude ('gapiclass. php '); $ objAPI = new GAPIClass ('aizasybizunrs81sa5vfpk8w4jtah2b49hzepre'); $ google = $ objAPI-> shorten ($ url); $ google = trim ($ google ); echo $ google; // print goo. gl resultecho"
"; // Begin x. co $ xco = 'http: // x. co/Squeeze. svc/text/9394242565bd41a384ae959cce%604? Url = '. $ longurl; // https://www.php1.cn/https://www.php1.cn/?apikey }? Url = $ xco = file_get_contents ($ xco); $ xco = trim ($ xco); echo $ xco; echo"
"; // End x. co} elseecho", the URL you entered is incorrect! "; // Sorry, something wrong with your url}?>
2.[Code]GAPIClass. php
_apiKey = $key;}public function shorten($longUrl){$postData = array('longUrl' => $longUrl);if(!is_null($this->_apiKey)){$postData['key'] = $this->_apiKey;}$jsonData = json_encode($postData);$curlObj = curl_init();curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/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);curl_close($curlObj);$json = json_decode($response);if($this->hasErrors($json)){return false;}else{return $json->id;}}private function hasErrors($json){if($this->keyWarning){if(is_null($this->_apiKey)){echo 'Currently you are not using an API key. It is recommended that you use one. Click here to learn more about the API key
';}}if(is_object($json)){if(isset($json->error)){foreach($json->error->errors as $error){$this->error.= $error->message.':'.$error->location.'; ';}return true;}}else{$this->error = 'Malformed JSON response';return true;}}}?>