Reputation: 138
I'm trying to use jBBCode to parse and de-parse bbcode into and from html.
When trying to get the html and turn that back in to bbcode, it just displays html. Here is the code I'm using to try and switch html back into bbcode.
$parser = new JBBCode\Parser();
$parser->loadDefaultCodes();
$parser->parse($MYHTMLSTRING);
echo $parser->getAsBBCode();
Does anyone know what I'm doing wrong here? I'm sure it's something very simple that I haven't figured out. Any help is appreciated! :D
Upvotes: 3
Views: 1008
Reputation: 30855
$parser->parse()
takes as input BBCode, not HTML.
After studying the documentation, it is my understanding that this is a one-way parser:
BBCode -> HTML
I believe the design is for you to store the BBCode in your database, and then when it is time to render HTML to visitors, you parse the BBCode at that time.
This way, you are always storing the raw, editable BBCode in the database.
This is a pretty common design-pattern. For example, for applications that use the Markdown Language (instead of BBCode), they typically store raw markdown in the database and only render it to HTML at page-load time.
In Summary:
Upvotes: 2