Jump to content

url/text shrink


Miguel Nunes

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
Link to comment
https://forums.phpfreaks.com/topic/12860-urltext-shrink/
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]
Link to comment
https://forums.phpfreaks.com/topic/12860-urltext-shrink/#findComment-49366
Share on other sites

Archived

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

×
×
  • Create New...

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.