Skip to content

Commit ef6e91a

Browse files
committed
preg_replace updated to preg_replace_callback
1 parent 5781dd8 commit ef6e91a

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

www/includes/utility.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -559,10 +559,15 @@ function prepare_comment_for_display ($text) {
559559
// Must go before the URL stuff.
560560
$text = htmlentities_notags($text);
561561
$link_length = 60;
562-
$text = preg_replace(
563-
"/((http(s?):\/\/)|(www\.))([a-zA-Z\d\_\.\+\,\;\?\%\~\-\/\#\='\*\$\!\(\)\&]+)([a-zA-Z\d\_\?\%\~\-\/\#\='\*\$\!\&])/e",
564-
'(strlen(\'$0\')>$link_length) ? \'<a href="$0">\'.substr(\'$0\',0,$link_length)."...</a>" : \'<a href="$0" rel="nofollow">$0</a>\'',
565-
$text);
562+
$text = preg_replace_callback(
563+
"/((http(s?):\/\/)|(www\.))([a-zA-Z\d\_\.\+\,\;\?\%\~\-\/\#\='\*\$\!\(\)\&]+)([a-zA-Z\d\_\?\%\~\-\/\#\='\*\$\!\&])/",
564+
function($matches) use ($link_length) {
565+
$url = $matches[0];
566+
return (strlen($url) > $link_length)
567+
? '<a href="' . $url . '">' . substr($url, 0, $link_length) . "...</a>"
568+
: '<a href="' . $url . '" rel="nofollow">' . $url . '</a>';
569+
},
570+
$text);
566571
$text = str_replace('<a href="www', '<a href="http://www', $text);
567572
$text = preg_replace("/([\w\.]+)(@)([\w\.\-]+)/i", "<a href=\"mailto:$0\">$0</a>", $text);
568573
$text = str_replace("\n", "<br>\n", $text);

0 commit comments

Comments
 (0)