Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.