By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,521 Members | 1,492 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,521 IT Pros & Developers. It's quick & easy.

Truncate & tag long URLs?

P: n/a
I'm looking for a way to truncate/ add-spaces & tag long URLs, so that

"Check this out http://www.example.com/hello-world/foo-bar.html it's
great"

would turn into

"Check this out <a
href="http://www.example.com/hello-world/foo-bar.html">http://www.exampl
e.com/hello-world/fo...</a> it's great"

or

"Check this out <a
href="http://www.example.com/hello-world/foo-bar.html">http://
www.example.com/ hello-world/ foo-bar.html</a> it's great"

This is because my discussion forums width is restricted and long URLs
break this.

Thanks!
-------------- Current attempts...

Adds a class which I then set to display blog, fixed width, and
overflow auto (creates newline problem though):

function tagLinks($str)
{
$pattern =
'#(^|[^\"=]{1})(http://|https://|ftp://|mailto:|news:)([^\s<>]+)([\s\n<>
]|$)#sm';
$str = preg_replace($pattern, "\\1<a class=\"forumlink\"
href=\"\\2\\3\">\\2\\3</a>\\4", $str);
$str = str_replace("\">http://", "\">", $str);
return $str;
}

Cuts off after domain (which is really bad at times):

function tagLinks($str)
{
$str = str_replace("-http:", "-temp:", $str);
$str = str_replace("<br />", " <br />", $str);
$str = preg_replace(
'/(http|https|ftp)+(s)?:(\/\/)((\w|\.)+)(\/)?(\S+)?/i', '<em><a
href="\\0">\\4</a></em>', $str );
$str = str_replace(" <br />", "<br />", $str);
$str = str_replace("-temp:", "-http:", $str);
return $str;
}
You can see the forum at <http://blog.outer-court.com/forum>.
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Philipp Lenssen wrote:
I'm looking for a way to truncate/ add-spaces & tag long URLs, so that

"Check this out http://www.example.com/hello-world/foo-bar.html it's
great"

would turn into

"Check this out <a
href="http://www.example.com/hello-world/foo-bar.html">http://www.exampl
e.com/hello-world/fo...</a> it's great"


Check out this thread:

http://groups.google.com/groups?thre...ing.google.com

--
USENET would be a better place if everybody read: | to email me: use |
http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
http://www.netmeister.org/news/learn2quote2.html | header, textonly |
http://www.expita.com/nomime.html | no attachments. |
Jul 17 '05 #2

P: n/a
Pedro Graca wrote:
Philipp Lenssen wrote:
I'm looking for a way to truncate/ add-spaces & tag long URLs

http://groups.google.com/groups?thre...245.39877e38%4
0posting.google.com


Thanks, that works great!

--
Google Blogoscoped
http://blog.outer-court.com
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.