Php 如何包装内部<;a href>;我的查询中出现的所有URL

Php 如何包装内部<;a href>;我的查询中出现的所有URL,php,regex,Php,Regex,好吧,我想我的问题的解决办法是使用正则表达式,但我目前对它的了解阻碍了我实现我想要的结果 因此,基本上,当被查询时,我如何使我的帖子/文本条目中出现的所有URL封装在元素中 当我echo$content时从数据库中,它将显示为: this is a link http://somerandomsite.com, check it out! 但是如何使文本中的链接在显示时包含在标记中 老实说,我不知道如何正确地编写语法。但这就是我想到的 //get url from content $link

好吧,我想我的问题的解决办法是使用正则表达式,但我目前对它的了解阻碍了我实现我想要的结果

因此,基本上,当被查询时,我如何使我的帖子/文本条目中出现的所有
URL
封装在
元素中

当我
echo$content时从数据库中,它将显示为:

this is a link http://somerandomsite.com, check it out!
但是如何使文本中的链接在显示时包含在
标记中

老实说,我不知道如何正确地编写语法。但这就是我想到的

//get url from content
$link = strstr($content, 'http://');

//insert <a href> for all $link inside $content
//then display $content with all links wrapped in <href>
//从内容获取url
$link=strstrstr($content,'http://');
//为$content内的所有$link插入
//然后显示包含所有链接的$content
$a=”这是一个链接http://somerandomsite.com,看看;
$a=preg\u replace(“/\b((?:http\:\/\/))|(?:www\))([^,]+)/”,“,”,$a);
echo$a;
不是吗:“我有一个问题。我决定用正则表达式来解决它。现在我有两个问题。”?无论如何:如果您不知道语法应该是什么,那么最合乎逻辑的步骤是首先。在使用文档作为参考试用regex之后,再次询问您的问题。
$a = 'this is a link http://somerandomsite.com, check it out!';

$a = preg_replace("/\b((?:http\:\/\/)|(?:www\.))([^ ,]+)/", "<a href=\"$1$2\">$1$2</a>", $a);

echo $a;