Browse Source

获取字符串中的连接地址

master
wanghongjun 5 months ago
parent
commit
5c0f478d7e
  1. 2
      app/common.php

2
app/common.php

@ -1058,7 +1058,7 @@ function preg_link($text){
return $text;
}
// 匹配更广泛的 URL 的正则表达式
$pattern ='/\b(?:https?:\/\/|ftp:\/\/)?([a-z0-9-+&@#\/%?=~_|!:,.;]*\.[a-z]{2,}(?:\/[a-z0-9-+&@#\/%?=~_|!:,.;]*)*)\b/i';
$pattern = '~(?:\b(?:https?|ftp)://[^\s<>]+(?::\d{1,5})?(?:/[^\s?#]*(?:\?[^\s#]*)?(?:\#[^\s]*)?)?|\bwww\.[^\s<>]+(?::\d{1,5})?(?:/[^\s?#]*(?:\?[^\s#]*)?(?:\#[^\s]*)?)?)(?!\w)~xi';
// 使用preg_replace()函数将URL转换为<a>标签
$replaced_text = preg_replace_callback($pattern, function($matches) {
$url = $matches[0];

Loading…
Cancel
Save