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

前端 未结 1 1546
自闭症患者
自闭症患者 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\]/', '<a href="\1">\2</a>', $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)
提交回复
热议问题