Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Shortening URL displays with php

Shortening URL displays with php
Thread Tools
Mac Elite
Join Date: Dec 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
Nov 20, 2004, 07:10 PM
 
I am running a website, where people post quite a few web links. They just copy and paste the "http.." part and the site automatically recognizes that as a link. After this the usual "<a hre.." part is added too. with the closing tag.

I would like a php script that can limit the length of the URl diplayed between the tags. Sometimes URLS are like 2-3 lines long and those can mess up the layout of our webpage.

What php code, functions could shorten only the displayed part of the url to some predefined number of characters?

Thank you,

t
     
Mac Elite
Join Date: Sep 2001
Location: The Land of Beer and Chocolates
Status: Offline
Reply With Quote
Nov 21, 2004, 10:54 AM
 
Originally posted by t_hah:
I am running a website, where people post quite a few web links. They just copy and paste the "http.." part and the site automatically recognizes that as a link. After this the usual "<a hre.." part is added too. with the closing tag.

I would like a php script that can limit the length of the URl diplayed between the tags. Sometimes URLS are like 2-3 lines long and those can mess up the layout of our webpage.

What php code, functions could shorten only the displayed part of the url to some predefined number of characters?

Thank you,

t
Something like this perhaps? (code not tested)
Code:
function shortenString($string) { $maxlength = 20; $prefixlength = 15; $suffixlength = 5; if (strlen($string) > $maxlength) { return substr($string, 0, $prefixlength)."...".substr($string, $maxlength - suffixlength - 1); } return $string; }
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:21 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2