Hello everyone i have a problem I have a text
$text = " some and text http://www.somelink2.com/html5.jpg and some text http://www.somelink.net/test/testjava/html5.html#fbid=QTb-X6fv5p1 some http://www.somelink4.org test and http://www.somelink3.org/link.html text and some text ";
i need to transform all text links http/s exept domains somelink3.org,somelink2.com they must be plain text
Something like this but with domains filter and not extention images:
function livelinked ($text){
preg_match_all("#((http|https|ftp)://(\S*?\.\S*?))(\s|\;|\)|\]|\[|\{|\}|,|\"|'|:|\<|$|\.\s)|^(jpg)^#ie", $text, $ccs);
foreach ($ccs[3] as $cc) {
if (strpos($cc,"jpg")==false && strpos($cc,"gif")==false && strpos($cc,"png")==false ) {
$old[] = "http://".$cc;
$new[] = '<a href="http://'.$cc.'" target="_blank">'.$cc.'</a>';
}
}
return str_replace($old,$new,$text);
}
edit: this helped me :
$text = preg_replace("~((?:http|https|ftp)://(?!site.com|site2.com|site3.com)(?:\S*?\.\S*?))(?=\s|\;|\)|\]|\[|\{|\}|,|\"|'|:|\<|$|\.\s)~i",'<a href="$1" target="_blank">$1</a>',$text);