preg_replace_callback of url in textarea 在下划线或冒号处截断

问题描述 投票:0回答:0

不确定如何继续允许或防止在此 preg_replace 中的 url 中的 underscorecolon 处剪断。也不确定我可能会遗漏哪些其他特殊字符会截断 url

$text = preg_replace_callback('@(https?://([-\w\.]+)+(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)?)@', function($m) {
   return '<a href="' . $m[1] . '" target="_blank">' . substr($m[1], 0, 75) . '</a>';
}, $text);
php regex preg-replace
© www.soinside.com 2019 - 2024. All rights reserved.