php - 在php中添加文本链接的链接,但前提是链接在我自己的网站中
问题描述
我知道这里有很多帖子可以将文本链接转换为可点击的链接。但我的情况有点不同。
我只想转换我网站上的链接。不是其他网站。
所以我尝试了:
$text = "The text you want to filter goes here. http://example.com/site/site";
echo preg_replace('$(\s|^)(https?://[example.com]+)(?![^<>]*>)$i', ' <a href="$2" target="_blank">$2</a> ', $text." ");
它可以工作,但问题是如果 url 包含类似:www.example.com/example/article/01/3232/ 如果只会获取 example.com。
任何想法如何让它按我的意愿工作?
解决方案
推荐阅读
- maven - maven:找不到本地安装的jar
- node.js - 在 node.js 中创建命令行工具的可能方法
- laravel - 试图访问 Laravel 中对象的元素但点击“未定义属性:stdClass::$code”
- android - 在 INtelliJ 中运行测试类时找不到类
- java - 为什么当我返回 object1-object2 时自制比较有效
- docker - 如何读取 dockerfile 中的 pod 信息
- python - 上下文管理器范围
- flutter - 为什么我不能将简单的图像添加到我的主页(Stless 小部件)?
- java - 如何在二维数组java中获得最小值
- google-ads-api - google adwords(googleads)的python api在调用OfflineConversionAdjustmentFeed操作时给出“INVALID_CONVERSION_TYPE”