Find all urls in text and shorten them

i have been working with twitter and needed to shorten urls
function 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);  
	  return $data;  
	}

function urlFinderShorten($text) {

        // limit the string to 140 characters
        $text = substr($text, 0, 140);
		
		// The Regular Expression filter
		$reg_exUrl = "/(http|https|ftp|ftps)://[a-zA-Z0-9-.]+.[a-zA-Z]{2,3}(/S*)?/";
		
		// Check if there is a url in the text
		if(preg_match($reg_exUrl, $text, $url)) {
		
			   // make the urls hyper links
			   return preg_replace($reg_exUrl, get_tiny_url($url[0]), $text);
		
		} else {
		
			   // if no urls in the text just return the text
			   return $text;
		
		}       
		
}