Let us create a Simple BBCode Parser function with PHP.
I guess you all know about BBCodes? BB code is a very simple set of codes (also known as BB tags) which is used to style or format the text displayed. When a text encapsulated with BB code is displayed in the browser, the BB tags are replaced with appropriate HTML tags. BBCodes are widely used in community sites, forums (like phpBB or vBulletin) and even blogs commenting section.
Here is an example BBCode and its actual output or formatted text.
BBCode: [b]bold text[/b]
Output: <b>bold text</b>
Learn more PHP Codes : Show user information like IP address, useragent with PHP codes
I guess you got the idea now. So now lets make the PHP function for this BBCode Parser.
BBCode Parser PHP function:
The above code will produce an output as shown:
This is bold and this is underlined and this is in italics with a red color
This is a simple PHP BBcode Parser function which use preg_replace() function to replace all the occurrence of BBcode with its corresponding HTML tags.