how do I make a bbcode to parse url tags into links?

前端 未结 1 1547
自闭症患者
自闭症患者 2021-01-25 18:28

How should I go about parsing a url in php? I wanna make it so it goes

[url=http://www.google.com]Google[/url]

Turns into:

<         


        
1条回答
  •  佛祖请我去吃肉
    2021-01-25 19:10

    $post = preg_replace('/\[url=(.+?)\](.+?)\[\/url\]/', '\2', $post);
    

    That will turn: [url=http://google.com]Google[/url]

    Into parsed bbcode text: Google

    You'll probably want to use more specific regex than just .+ to filter out potentially bad/dangerous input.

    0 讨论(0)
提交回复
热议问题