Generate A Tinyurl Amongst Php

TinyURL allows you lot to direct keep a long URL similar "http://www.developer-paradize.blogspot.com" in addition to plough it into "http://tinyurl.com/n48rbym". Using the PHP in addition to TinyURL API, you lot tin usage these tiny URLs on the fly!. Simply supply the URL in addition to you'll received the new, tiny URL inward return.

PHP
<?php //gets the information from a URL business office get_tiny_url($url)  { $ch = curl_init(); $timeout = 5;  curl_setopt($ch,CURLOPT_URL,'http://tinyurl.com/api-create.php?url='.$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); $data = curl_exec($ch); curl_close($ch); render $data; } //test it out! $new_url = get_tiny_url('http://www.developer-paradize.blogspot.com/');  //returns http://tinyurl.com/n48rbym echo $new_url; ?> 
If you lot don't desire to role cURL, you lot tin role file_get_contents.
PHP
 <?php business office tinyurl($url) { render file_get_contents('http://tinyurl.com/api-create.php?url='.$url); } //test it out! $url = tinyurl('http://www.developer-paradize.blogspot.com/'); //returns http://tinyurl.com/n48rbym echo $url; ?> 

Note: If the server has disabled the file_get_contents() it volition usage unwanted problem. So I strongly recommend to role cURL() in addition to it volition run fine.


Sumber http://developer-paradize.blogspot.com

Comments

Popular posts from this blog

What Are The Main Components of a Computer System

Top Qualities To Look For In An IT Support Team

How To Integrate Google Adwords Api Into Codeigniter?