小编jsb*_*jsb的帖子

PHP 在字符串中查找 URL 并建立链接。如果尚未在链接中

我想在链接尚未在链接中的字符串中查找 URL

我当前的代码:

$text = "http://www.google.com is a great website. Visit <a href='http://www.google.com' >http://google.com</a>"
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";


if(preg_match($reg_exUrl, $text, $url)) {
   $links = preg_replace($reg_exUrl, '<a href="'.$url[0].'" rel="nofollow">'.$url[0].'</a>', $_page['content']['external_links']);

}
Run Code Online (Sandbox Code Playgroud)

问题在于它返回了两次链接(这就是它返回的内容):

<a href="http://www.google.com" rel="nofollow">http://www.google.com</a> is a great website. Visit <a href='<a href="http://www.google.com" rel="nofollow">http://www.google.com</a>' ><a href="http://www.google.com" rel="nofollow">http://www.google.com</a></a>
Run Code Online (Sandbox Code Playgroud)

php hyperlink preg-replace preg-match

5
推荐指数
1
解决办法
5883
查看次数

如何在CSS中设置数据描边样式

如何通过数据划线设置范围.

例如.在我的HTML中有:

<span data-scribe="element:verified_badge">?</span>
Run Code Online (Sandbox Code Playgroud)

我怎样才能在这个特定范围内添加CSS样式?

html css

0
推荐指数
1
解决办法
1182
查看次数

标签 统计

css ×1

html ×1

hyperlink ×1

php ×1

preg-match ×1

preg-replace ×1