替换文本字符串中的任何url,以php链接到可点击的链接 [英] replace any url's within a string of text, to clickable links with php
本文介绍了替换文本字符串中的任何url,以php链接到可点击的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我有一串文字,例如
$text = "Hello world, be sure to visit http://whatever.com today";
我(可能使用正则表达式)如何插入链接的锚标记(将链接本身显示为链接文本)?
how can i (probably using regex) insert the anchor tags for the link (showing the link itself as the link text) ?
推荐答案
您可以使用regexp来做到这一点:
You can use regexp to do this:
$html_links = preg_replace('"\b(https?://\S+)"', '<a href="$1">$1</a>', $text);
这篇关于替换文本字符串中的任何url,以php链接到可点击的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文