Dear ones,
I really need a script for my blog, but I can't figure out how to make it.
In my blog I allow visitors to post comments. For security reasons,
I don't allow them to insert HTML tags. So when a user posts a comment,
that comment is processed by PHP so that "<" and ">" are converted to
HTML entities. Tags are displayed but do not work, since they're not parsed
by the browser as HTML tags.
But what if the user tries to insert a link in his/her comment by simply typing the address?
It will appear as this: htttp://www.example.com/index.php?parameter=etc
But I want it to appear as a clickable link:
http://www.example.com/index.php?parameter=etc
So I wrote this function.
PHP Code:
function parse_links($text) {
$text = ereg_replace('http([^\ <>]+)','<a href="http\\1">http\\1</a>',$text);
return $text;
}
So the link is parsed and transformed into a clickable link <a href="...">...</a>
That's the point: if the user inserts a very, very long link,
the design of my blog will be destroyed.
Example: htttp://www.example.com/index.php?parameter=1¶meter=1¶meter=1¶ meter=1¶meter=1¶meter=1¶meter=1¶me ter=1¶meter=1¶meter=1
So I do need a function that CUTS the link after the 30th character, something like this:
http://www.example.com/index.php?par...=1¶meter=1
Can you help me?
Thank you for your patience and attention.