nuttycoder Posted August 14, 2009 Share Posted August 14, 2009 I have a problem, I have an app that reads my emails when there is a really long url in the messag such as: http://www.domain.com/editaccount.php?notifications&md=ZmVlZF9jb21tZW50O2Zyb209NTA5MTM2MzA2O3VpZD03MTcxNTI4Mjk7b3duZXI9NzE3MTUyODI5O29pZD0xMzYzMTcxNTE1MTQ7dG89NzE3MTUyODI5&mid=edf630G2abee23dG2677304G36 It creates a scrollbar is there anyway I can shorten/modify the url so it stays in tact but have spaces maybe so it would go to a new line rather then creating a scrollbar. Any advice would be helpful Thanks. Link to comment https://forums.phpfreaks.com/topic/170233-solved-dealing-with-really-long-urls/ Share on other sites More sharing options...
oni-kun Posted August 14, 2009 Share Posted August 14, 2009 If you mean to stop if from going offscreen, then use PHP's wordwrap() function, it'll automatically place a newline after every xx characters.. <?php $url = "http://www.domain.com/editaccount.php?notifications&md=ZmVlZF9jb21tZW50O2Zyb209NTA5MTM2MzA2O3VpZD03MTcxNTI4Mjk7b3duZXI9NzE3MTUyODI5O29pZD0xMzYzMTcxNTE1MTQ7dG89NzE3MTUyODI5&mid=edf630G2abee23dG2677304G36 "; $wrappedurl = wordwrap($url, 20, "\n"); echo $wrappedurl; ?> Link to comment https://forums.phpfreaks.com/topic/170233-solved-dealing-with-really-long-urls/#findComment-897993 Share on other sites More sharing options...
nuttycoder Posted August 14, 2009 Author Share Posted August 14, 2009 thanks just tried it and the output is the same like this: http://www.domain.com/editaccount.php?notifications&md=ZmVlZF9jb21tZW50O2Zyb209NTA5MTM2MzA2O3VpZD03MTcxNTI4Mjk7b3duZXI9NzE3MTUyODI5O29pZD0xMzYzMTcxNTE1MTQ7dG89NzE3MTUyODI5&mid=edf630G2abee23dG2677304G36 Link to comment https://forums.phpfreaks.com/topic/170233-solved-dealing-with-really-long-urls/#findComment-898009 Share on other sites More sharing options...
thebadbad Posted August 14, 2009 Share Posted August 14, 2009 Have a look at this recent thread: http://www.phpfreaks.com/forums/index.php/topic,264352.0.html Link to comment https://forums.phpfreaks.com/topic/170233-solved-dealing-with-really-long-urls/#findComment-898011 Share on other sites More sharing options...
Daniel0 Posted August 14, 2009 Share Posted August 14, 2009 Maybe something like this? <?php function truncateLink($link, $maxLength) { $length = strlen($link); if (strlen($link) <= $maxLength) { return $link; } $split = floor(($maxLength - 3) / 2); return substr($link, 0, $split) . '...' . substr($link, -$split); } $link = 'http://www.domain.com/editaccount.php?notifications&md=ZmVlZF9jb21tZW50O2Zyb209NTA5MTM2MzA2O3VpZD03MTcxNTI4Mjk7b3duZXI9NzE3MTUyODI5O29pZD0xMzYzMTcxNTE1MTQ7dG89NzE3MTUyODI5&mid=edf630G2abee23dG2677304G36'; printf('<a href="%s">%s</a>', $link, truncateLink($link, 50)); Link to comment https://forums.phpfreaks.com/topic/170233-solved-dealing-with-really-long-urls/#findComment-898013 Share on other sites More sharing options...
nuttycoder Posted August 14, 2009 Author Share Posted August 14, 2009 thank you that works perfectly! Link to comment https://forums.phpfreaks.com/topic/170233-solved-dealing-with-really-long-urls/#findComment-898094 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.