![]() |
||||
|
||||
|
« GIDPanel - Member's Area is now open | How Does a Credit Card Transaction Get Processed? » |
BBCode - the [quote] tag
by: JdS - May 05, 2005
I spent the last 2 days figuring out how to write PHP codes to process [QUOTE] bb code tags. It seemed like an easy thing to do until I actually sat down to write the whole thing. Sometimes "knowing too much" can be a bad thing - in this particular instance, it really was! I started writing this little function using the PHP preg_match_all function. It worked really well but it failed miserably when there were nested [quote] bb code tags to be found anywhere in the text. Anyway, to make a long story short, I finally decided to "think differently" and re-wrote the function from the ground up... and so far, so good! PHP function - QUOTE BB CodeLet's assume you have an example text that contains one or more [quote] bbcode tags and it looks something like this: Generic Code Example: Some text dummy text quoted from [url=http://www.lipsum.com/]http://www.lipsum.com/[/url] [quote][b]What is Lorem Ipsum?[/b] Lorem Ipsum is simply dummy text of the printing and typesetting industry.[/quote] Still some more: [quote][b]Where does it come from?[/b] Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.[/quote] Now that we have a sample to work with, let me show you how I wrote the function to process the [quote] bbcode tags on this site. PHP Code Example:
Example output - QUOTE BB CodeTo see the resulting output, lets paste that example text in [quote] tags right here inside this article, just to see how it handles nested [quote] tags.
For (web) display purposes, you can now simply customise the CSS selector for <blockquote> tag in your HTML!
|
GIDNetwork Sites
Archives
Recent GIDBlog Posts
Recent GIDForums Posts
Contact Us
|
« GIDPanel - Member's Area is now open | How Does a Credit Card Transaction Get Processed? » |