Help needed in truncating links

Status
Not open for further replies.

deAthbLisS

Active Member
1,393
2009
61
10
Hi,
I need help in truncating links.. if you know how to do this please post the methods.. Preferred methods: css or javascript.

i have long links like:
Code:
http://www.google.co.in/search?hl=en&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&q=download+movies&aq=f&aqi=g10&aql=&oq=&gs_rfai=

I want them to be converted to with linking.. :
Code:
http://www.google.co.in/search?hl....=&oq=&gs_rfai=
example:
http://www.google.co.in/search?hl=e...ownload+movies&aq=f&aqi=g10&aql=&oq=&gs_rfai=

so that any link posted or added in the page will appear like that..

Thanks
 
1 comment
PHP:
function truncate(string)
{
    var patcher = ".......";
    if(string.length > (30+ patcher.length))
    {
         firstSegment = ((string.length/2)-patcher.length);
         lastSegment = (string.length-patcher.length);
         return string.substr(0,firstSegment) + patcher + string.substr(lastSegment,30);
    }
    return string;
}
alert(truncate("some ling ass text string. cossdjgsinuhguynuadgfudkyfgsydfnsydjfhsdfgsfdgkgh ieurhg iuedhg uaegh uaergh aeuihfg ioah laergm"));

Shows some ling ass text string. cossdjgsinuhguynuadgfudkyfg....... laergm

http://jsfiddle.net/7GHzm/1/
 
Status
Not open for further replies.
Back
Top