Jump to content

Archived

This topic is now archived and is closed to further replies.

Miguel Nunes

url/text shrink

Recommended Posts

hello, how can i shrink some text or a url? i mean, in Invision Power Board it shrinks big urls makes them like this: [a href=\"http://www.urlurlurlurlurl...........urlurl.com/\" target=\"_blank\"]http://www.urlurlurlurlurl...........urlurl.com/[/a]

i want to do the same with text, is this possible? How?

Thank you!
Miguel

Share this post


Link to post
Share on other sites
This should work for you.

You can add in things like removing the http:// from the displayed link using str_replace and such if you want. You could also very easily create a function from this.

[code]$url = "http://www.oneverylongurl.com/longlonglonglonglonglonglonglonglong.html";

//pick a number for the max length
//15 is kind of short, but should get the point across
$maxlength = 15;

//the number of characters to be displayed from the
//beginning of the url...should be less than $maxlength
$beginning = 8;

//number of chars from the end of the url
$end = 7;

if (strlen($url) > $maxlength) {
    $link = "<a href=" . $url . ">" . substr($url, 0, $beginning) . "..." . substr($url, -$end, $end) . "</a>";
} else {
    $link = "<a href=" . $url . ">" . $url . "</a>";
}

echo $link;[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.