Fixed a flaw in the regex preventing URLs at the very end of a string to be changed into links

This commit is contained in:
pezcurrel 2024-08-22 11:51:42 +02:00
parent 40ceb04d2e
commit 49c34d6949

View file

@ -4,7 +4,7 @@ function text2html($text,$ifnoe) {
if (is_null($text) || preg_match('#^\s*$#',$text)===1)
return $ifnoe;
$text=htmlspecialchars($text,ENT_QUOTES|ENT_HTML5,'UTF-8');
$text=preg_replace('#(https?://.+?)(\n|\s|\W\s|\W\n)#','<a href="$1" target="_blank">$1</a>$2',$text);
$text=preg_replace('#(https?://.+?)(\n|\s|$|\W\s|\W\n|\W$)#','<a href="$1" target="_blank">$1</a>$2',$text);
$text=nl2br($text);
return $text;
}