August 9th, 2000, 04:04 PM
-
I've written a function to format a string from a form before it is displayed on the web page. I use the function to fix html-characters and line-breaks, allow som UBB-like coding and make all words starting with http:// or ftp:// hyperlinks.
The problem is that if there is any form of punctuation after the url, the script adds that to the hyperlink as well, which means that I end up with bad url:s. Here's the function:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
function fixOutput($string, $addlinks) {
$string = htmlentities($string);
$string = str_replace('', '<B>', $string);
$string = str_replace('', '</B>', $string);
$string = str_replace('', '<I>', $string);
$string = str_replace('', '</I>', $string);
if ($addlinks == true) {
$string = ereg_replace("((ftp://)|(http://))(([[:alnum:]]|[[
unct:]])*)", "<A HREF="