gpt4 book ai didi

php - 将文本字符串中的任何 url 替换为带有 php 的可点击链接

转载 作者:可可西里 更新时间:2023-11-01 13:06:45 25 4
gpt4 key购买 nike

假设我有一串文本,例如

$text = "Hello world, be sure to visit http://whatever.com today";

我如何(可能使用正则表达式)为链接插入 anchor 标记(将链接本身显示为链接文本)?

最佳答案

您可以使用正则表达式来执行此操作:

$html_links = preg_replace('"\b(https?://\S+)"', '<a href="$1">$1</a>', $text);

关于php - 将文本字符串中的任何 url 替换为带有 php 的可点击链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1798912/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com