相关疑难解决方法(0)

如何使用 bbcode 标签的值将 bbcode url 标签转换为 html 超链接?

如何将 bbcode[url]标签转换为<a>在开始和结束标签之间具有 href 属性和文本的标签?

以下是一些示例字符串:

[url]https://any.com/any[/url]

[URL="https://any.com/any?any=333"]text text[/URL]

[url]http://www.any.com/any?any=44#sss[/url]

*请注意,开始[url]标记中的双引号子字符串是可选的,并且会影响所需的输出...

我试过这种模式:

(?:\[url="(https?://(?:www)?.+?)\]|\[url\](https?://(?:www)?.+\[)) 
\[url="(https?:\/\/(?:www\.)?.+?)\]|\[url\](https?:\/\/(?:www\.)?.+)\[\/url\]
\[url="(https?:\/\/(?:www\.)?.+)"\]|\[url\](https?:\/\/(?:www\.)?.+)\[\/url\]
Run Code Online (Sandbox Code Playgroud)

像这样:

$pattern ='##i';
$text = preg_replace($pattern,'',$text);
Run Code Online (Sandbox Code Playgroud)

从上面的 bbcode url 标签中,我想要的结果应该是:

<a href="https://any.com/any">https://any.com/any</a>

<a href="https://any.com/any?any=333">text text</a>

<a href="http://www.any.com/any?any=44#sss">http://www.any.com/any?any=44#sss</a>

换句话说,如果 url 位于开始[url]标记的双引号部分,则使用该值作为href值并将[url]标记的 innerHTML保留为生成的<a>标记的 innerHTML 。

如果URL不在双引号部分,但位于打开和关闭之间的[url]标签,然后使用该值作为这两个href值和的的innerHTML <a>

php regex bbcode hyperlink preg-replace

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

标签 统计

bbcode ×1

hyperlink ×1

php ×1

preg-replace ×1

regex ×1