sfBBCodeParserPlugin - 0.2.2

BBCode parser plugin for symfony

You are currently browsing
the website for symfony 1

Visit the Symfony2 website

« Back to the Plugins Home


Forgot your password?
Create an account



advanced search
Information Readme Releases Changelog Contribute
Show source | Show as Markdown

sfBBCodeParser plugin

The sfBBCodeParser plugin is a plugin which provides a powerful and extensible parser for the popular BBCode formatting syntax. It is designed with the possibility of extension in mind. This parser does not simply use regular expressions to replace the bbcodes-- it parses the entire string using a recursive parse method, and ensures that all tags that require closing tags are closed in the proper order, thereby ensuring XHTML-compliant output.


  • Download the most recent package below
  • Unzip into your plugins folder


The parse_bbcode helper is extremely easy to use:


This code snippet will parse the provided $string for any bbcodes currently in the database, replace the bbcodes with XHTML-formatted text, and echo that formatted text.


The plugin provides a handful of default tags included. However, you can add more (or override the current ones) by creating a app/<yourapp>/config/bbcode.yml file. It uses the YAML format, which you should be familiar with. The structure of the file should be as follows:

    name:     Bold                         # Name for your tag.  Right now it does nothing.
    help:     Make the selected text bold  # Description of the effect of the tag.  Right now it too does nothing
    tag:      b                            # Tag to be matched.  No spaces allowed.  This needs to match the key for the whole tag (the line with 2 spaces), or strange things will happen.
    pattern:  <strong>${content}</strong>  # The pattern to be used.  ${content} will be replaced with the content of the tag. ex. [b]content[/b]
                                           #   ${attr} will be replaced with the attribute value.  ex. [color=attr]content[/color]
    selfclose: no                          # If the tag closes itself (ex. a horizontal rule), set this to true.  Otherwise it's not needed.  Self-closing tags should not have a closing tag.
  ...more tags here...
  openchar:   '['                          # Set this to whatever character you want to signal the opening of your tags
  closechar:  ']'                          # Set this to whatever character you want to signal the closing of your tags

The comments should explain it for the most part.


Right now the parser only supports the one attribute . I've seen a suggestion that it handle multiple attributes. Right now I don't feel like adding this in. Maybe in the future...


  • Finish the BBCode editor