Miguel Nunes Posted June 25, 2006 Share Posted June 25, 2006 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 More sharing options...
hitman6003 Posted June 25, 2006 Share Posted June 25, 2006 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 More sharing options...
Miguel Nunes Posted June 25, 2006 Author Share Posted June 25, 2006 thanks ;) Link to comment https://forums.phpfreaks.com/topic/12860-urltext-shrink/#findComment-49384 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.