Jump to content


Photo

url/text shrink


  • Please log in to reply
2 replies to this topic

#1 Miguel Nunes

Miguel Nunes
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 25 June 2006 - 12:02 PM

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

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 25 June 2006 - 02:23 PM

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.

$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;


#3 Miguel Nunes

Miguel Nunes
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 25 June 2006 - 03:19 PM

thanks ;)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users