Simple BBparser in PHP that lets you replace content outside tags

前端 未结 2 1473
北荒
北荒 2021-01-27 09:34

I\'m trying to parse strings that represent source code, something like this:

[code lang=\"html\"]
  <div>stuff</div>
[/code]
相关标签:
2条回答
  • 2021-01-27 10:00

    HTML Purifier http://htmlpurifier.org/

    But you are facing same issues just like in your 20 previous questions.

    0 讨论(0)
  • 2021-01-27 10:10

    Do you guys know a BB parser class written in PHP that I can use for this, instead of regexes?

    There's the BBCode PECL extension, but you'd need to compile it.

    There's also PEAR's HTML_BBCodeParser, though I can't vouch for how effective it is.

    There are also a few elsewhere, but I think they're all pretty rigid.

    I don't believe that either of those do what you're looking for, with regard to having a callback for tag contents (and then @webarto is totally correct in that HTMLPurifier is the right tool to use when processing the contents). You might have to write your own here. I've previously written about my experiences doing the same that you might find helpful.

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