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($p attern, "\\1<a class=\"forumli nk\"
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("<b r />", " <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>.
"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($p attern, "\\1<a class=\"forumli nk\"
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("<b r />", " <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>.
Comment