Jump to content

[SOLVED] Dealing with really long urls


nuttycoder

Recommended Posts

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

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

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

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.