开发者

BBCode parser without Regex? [closed]

Closed. 开发者_JAVA百科This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 4 years ago.

Improve this question

I'm looking for a BBCode parser in Javascript or PHP without the need of using Regex. Can anybody suggest me a good one?


It is recommended to use regex.

Other solution:

function bb_parse($str)
{
    return str_replace(array('[b]', '[/b]'), array('<strong>', '</strong>'), $str);
}

This can break parsing due to mis-closing tags can end up content being wrapped with a HTML tag without closing.


There's a PECL extension for bbcode. You'll need to take a look on how to install PECL extensions in order to utilize it.


Zend parser might be what you're looking for http://framework.zend.com/manual/en/zend.markup.parsers.html

Unfortunately, I found it the least practically functional of the BBCode parsers I evaluated: when encountering malformed markup ([b] asdf [/ wops I forgot to close my tag) it tends to throw away all content after the first malformed tag. Other bbcode parsers do a much better job of simply ignoring bad markup.


So I know you said no regex, but I recently wrote a BBCode parser in JavaScript, and I believe it addresses your concerns since it is not a simple find and replace and it gives you access to the content within the tags. You can see a demo of it here:

http://patorjk.com/bbcode-previewer/

And get the source and write up on it here:

http://patorjk.com/blog/2011/05/07/extendible-bbcode-parser-in-javascript/


I recently write a bbcode parser in javascript.

What it can do:

  1. Convert BBcode string to HTML string;
  2. Convert HTML element to BBCode string;
  3. Auto correct BBCode string;

Check the demo: UBBParser


If you can install a PECL extension, you will be able to use the BBCode functions

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜