Hello to everyone. I need to do this :
when a user insert a BBCode tag, with preg_replace and regex i do some trasformation.
e.g.
function forumBBCode($str){
$format_search=array(
'#\[url=(.*?)\](.*?)\[/url\]#i'
);
$format_replace=array(
'<a class="lforum" target="_blank" href="$1">$2</a>'
);
$str=preg_replace($format_search, $format_replace, $str);
$str=nl2br($str);
return $str;
}
now i want also this : when a user insert a normal text with a link, this must be trasformed too. i can't do this trought preg_replace function, because if i write a code as
$format_search
'#(www\..*?)#i'
$format_replace
'<a class="lforum" target="_blank" href="$1">$1</a>'
it will convert the link 2 time (in the [url] and when the link is without this tag).
so i think to this function :
function checkLinks($string) {
$arrelab="";
$arr=split(' |\r\n', $string);
for($i=0; $i<sizeof($arr); $i++) {
echo $i." - ".$arr[$i]."<br/>";
if ((strpos($arr[$i], 'www.')!==false) or (strpos($arr[$i], 'http://')!==false) or (strpos($arr[$i], 'ftp://')!==false)) {
if (strpos($arr[$i], '[url=')===false) {
$arr[$i]='<a class="lforum" target="_blank" href="'.$arr[$i].'">'.$arr[$i].'</a>';
}
}
$arrelab=$arrelab." ".$arr[$i];
}
return $arrelab;
}
the problem is that i need a split as for the newline, as for the empty space. any help would be appreciated.
p.s. sorry for my bad english :)
cheers