Connecting Tech Pros Worldwide Help | Site Map

How to use Tinyurl.com dynamically

Newbie
 
Join Date: May 2009
Posts: 9
#1: Jun 25 '09
I have a feedback Form from which my visitors send their views. At times, I see very long URLs get submitted via my Form and get entered into my database. But, when displaying the URL, my page gets distorted..

Is there a way I can script this so I can automatically convert this long URL to a small url using TinyURLcom for instance - like what Twitter does..

i.e. I want to shorten this long URL automatically before it is inserted into the database

From:
Expand|Select|Wrap|Line Numbers
  1. http://rover.ebay.com/rover/1/711-53200-19255-0/1?t
  2. ype=3&campid=5336224516&toolid=10001&customid=tiny-
  3. hp&ext=unicycle&satitle=unicycle
To
Expand|Select|Wrap|Line Numbers
  1. http://tinyurl.com/bv5tgg
Thank you.

-AJ
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Jun 25 '09

re: How to use Tinyurl.com dynamically


If you want to create a Tiny URL.com URL, then you will have to make a HTTP request to the create.php page of TinyURL.com, but if the only reason for this is the display, then how about shortening the URL when displaying, e.g.
Expand|Select|Wrap|Line Numbers
  1. <a href="http://rover.ebay.com/rover/1/711-53200-19255-0/1?type=3&campid=5336224516&toolid=10001&customid=tiny-hp&ext=unicycle&satitle=unicycle">http://rover.ebay.com/...</a>
or specify link text as well as the link itself.
Newbie
 
Join Date: May 2009
Posts: 9
#3: Jun 25 '09

re: How to use Tinyurl.com dynamically


aCoder -

Your solution would work only if I have a field that collects URLs only, however, my field is a textarea, the visitors are allowed to put text in this field, but at times, they paste URLs too within the text – that is the issue I am facing with.

If there is a long URL berried within the text, how do I shorten it or worse case scenario, how do I prevent/strip a URL before it gets inserted into the database.

Thanks
-AJ
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#4: Jun 26 '09

re: How to use Tinyurl.com dynamically


Oh, I see. Well, in that case, parse the field value. You could use a regular expression to replace links with the shorter display by using REReplace.
Reply