hi there,
i wrote this function to format text for my news section on my site, so that all links would turn into actual links, but i can't seem to get it to work, can anyone see why?
ps, this is one of my first attempts at PHP, it's amazing how much a bit of actionscript knowledge can get u
function formatmessage($message){
$j = 0;
$message = trim($message);
$message = str_replace(chr(13) & chr(10), " <BR> ", $message);
$message = str_replace(chr(10) , " <BR> ", $message);
$message = str_replace(chr(13) , " <BR> ", $message);
$message = str_replace("'", "''", $message);
$message = str_replace(chr(22), chr(22) & chr(22), $message);
$msgarray = array();
$msgarray = explode(" ", $message);
foreach($msgarray as $i){
if (stristr($i, "www.")){
$msgarray[$j] = "<a target=blank href=http://" & $i & ">" & $i & "</a>";
}
if (stristr($i, "http://")){
$msgarray[$j] = "<a target=blank href=" & $i & ">" & $i & "</a>";
}
if (stristr($i, "www.")){
$msgarray[$j] = "<a target=blank href=http://" & $i & ">" & $i & "</a>";
}
if (eregi( "[.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$", $i)){
$msgarray[$j] = "<a href=mailto:" & $i & ">" & $i & "</a>";
}
$j = $j+1;
}
$formatmessage = implode(" ", $msgarray);
return $formatmessage;
}