I’m working on a custom CMS in Codeigniter and I’m trying to allow users to use custom tags instead of having to place HTML into posts.
For example, if a person is posting about a game and want to include a stylized button as a call to action, they would just type [button=http://example.com]Play this game[/button] instead of the HTML <div class="action-button"><a href="http://example.com">Play this game</a></div>
Obviously, this is a simple example. Some more complex things I’d like to do would be something like which would include an image gallery with an ID of 120.
I’ve been searching and I haven’t had much luck. I feel like there’s another word for what I’m trying to do but it’s just not coming to me, maybe that would yield better search results.
Any tips to get me going would be appreciated.
The term you’re looking for is BBCode (Bulletin Board Code).
As for parsing you could look at some forum apps and perhaps CI’s template parser for inspiration. Like Jarrett already mentioned they mostly utilize
str_replace()andpreg_replace()functions.Something like
would be more advanced though.