我正在尝试编写一个函数来在 URL 之前和之后的字符串中插入一些东西(如果有的话)。例如,一个字符串可能是这样的
"This is a string and some links, http://www.abc.com/xyz.html&p=123 and the other link is http://www.xyz.com/abc.html&x=2, that's all."
我想将其更改为(在 URL 之前和之后添加一些 html 标签)
"This is a string and some links, <a href="...">http://www.abc.com/xyz.html&p=123</a> and the other link is <a href="...">http://www.xyz.com/abc.html&x=2</a >, that's all."
实际上,我之前编写了一个 Lua 函数,通过使用 string.find() 来查找 http 并递归地解析字符串来做类似的事情。
我对 PHP 比较陌生,想知道 PHP 是否有任何功能或技术可以更轻松地执行此任务?