PHP beginner |
|
Aha, dit is iets waarmee ik m'n reguliere expressiekennis van 4 dagen eens mee kan testen... een probeersel:
<?
if(!preg_match("/(\$@{})+/",$text)) {
if(preg_match("/http:\/\/(.*)([[:space:]*])/",$text)) {
$text = preg_replace("/http:\/\/([a-zA-Z0-9\._-]*[\/\.\?\&;_\\=\-a-zA-Z0-9]*)/si","<a href=\"http://\\1\" target=\"_blank\">http://\\1</a>",$text);
}
elseif(preg_match("/www([a-zA-Z0-9\/\.\?\&\;\_\\\=\-]*)/",$text)) {
$text = preg_replace("/www\.([\/\.\?\&;_\\=\-a-zA-Z0-9]*)([[:space:]]?)/si","<a href=\"http://www.\\1\" target=\"_blank\">http://www.\\1</a>",$text);
}
}
?>
<? if(preg_match("/http:\/\/(.*)([[:space:]*])/",$text)) { $text = preg_replace("/http:\/\/([a-zA-Z0-9\._-]*[\/\.\?\&;_\\=\-a-zA-Z0-9]*)/si","<a href=\"http://\\1\" target=\"_blank\">http://\\1</a>",$text); } elseif(preg_match("/www([a-zA-Z0-9\/\.\?\&\;\_\\\=\-]*)/",$text)) { $text = preg_replace("/www\.([\/\.\?\&;_\\=\-a-zA-Z0-9]*)([[:space:]]?)/si","<a href=\"http://www.\\1\" target=\"_blank\">http://www.\\1</a>",$text); } } ?>
Invoer is dus een $txt string, en uitvoer is diezelfde string |