将字符串转换为 Laravel 中的 html 超链接

Converting string into html hyperlinks in Laravel

我正在使用此代码从 Laravel:

中的帖子中获取 hyperlink links
{!! preg_replace('@(http(s)?)?(://)?(([a-zA-Z])([-\w]+\.)+([^\s\.]+[^\s]*)+[^,.\s])@', '<a href="http://" target="_blank" title="[=12=]">[=12=]</a>', nl2br(e($post))) !!}

但是如果我输入这个:

你好

你好吗?

我觉得很奇怪 link "Hello. /> How are you?"。

我该怎么办?我不知道如何使用正则表达式。我只想使用 hyperlink 以 http://、https://、www. 开头的字符串,而不是像 anyword.anydomain.

这样的 links

我找到的最佳解决方案是这个库:https://github.com/misd-service-development/php-linkify

$linkify = new \Misd\Linkify\Linkify();
$text = 'This is my text containing a link to www.example.com.';
echo $linkify->process($text);

会输出:

这是我的文字,其中包含 link 到 www.example.com