To reduce the number of URLs in the text, put the API stuff in a function that takes a long URL and returns a short URL. Then apply this function using the PHP function preg_replace_callbackto your text. It will look something like this:
<?php
function shorten_url($matches) {
$long_url = $matches[0];
$url = "http://tinyurl.com/api-create.php?url=$long_url";
return file_get_contents($url);
}
$text = 'I have a link to http://www.example.com in this string';
$textWithShortURLs = preg_replace_callback('|http://([a-z0-9?./=%#]{1,500})|i', 'shorten_url', $text);
echo $textWithShortURLs;
?>
, " " - , , - .
. http://php.net/preg-replace-callback