scheme 0 Report post Posted August 13, 2005 (edited) THIS BBCODE TUTORIAL was found to be copied. -- TUTORIAL EDITED -- Edited September 17, 2005 by OpaQue (see edit history) Share this post Link to post Share on other sites
karlo 0 Report post Posted August 13, 2005 This tutorial is really usefull for PHP programmers. I suggest including the original RegEx thingy before the PregEx thingy. Did you get what I said? It's really hard to explain. Again, this is a really usefull tutorial! Good job! Share this post Link to post Share on other sites
scheme 0 Report post Posted August 13, 2005 I'm not really sure what you mean exactly, but the regex have to be designed before the preg_replace() call Share this post Link to post Share on other sites
beeseven 0 Report post Posted August 13, 2005 Very nice, I always wondered what the stuff in preg_replace meant. Share this post Link to post Share on other sites
MXBrandon 0 Report post Posted September 13, 2005 Thanks for the great tutorial, this has helped me a ton! Â One thing I would recommend adding however is the i modifier. This will make the bbcode case insensitive. For example: Â Bold and Bold will both be changed instead of just the first one. To do this, add an "i" after the last slash in each line of the regex statement. Â Example: $regexes = array( "/\[b\]([\D\S]+?)\[\/b\]/i" "/\[i\]([\D\S]+?)\[\/i\]/i" "/\[u\]([\D\S]+?)\[\/u\]/i" "/\+)\]([\D\S]+?)\[\/url\]/i" "/\[img\]([\D\S]+?)\[\/img\]/i" ); Share this post Link to post Share on other sites
thablkpanda 0 Report post Posted September 13, 2005 Excellent work. Good for people trying to make their own CMS'es/Forums/etc, straight out the ground with PHP.Panda Share this post Link to post Share on other sites
MXBrandon 0 Report post Posted September 13, 2005 (edited) Is there a way make nested codes work? For example, using the code provided above, if someone types in this: [colorx=red]red text[colorx=blue]blue text[/colorx]back to red[/colorx] We "want" this result:<font color="red">red text<font color="blue">blue text</font>back to red</font>However, this is the result that the code produces:<font color="red">red text[colorx=blue]blue text</font>back to red[/colorx] (note: I used 'colorx' instead of 'color' so the forum would not parse the code)For the record, different nested codes work, such as italics within bold, but like codes dont work, such as a bold inside of a bold, quote inside of a quote, color inside of a color, etc. Notice from cmatcmextra: Please use CODE tags when writing codes. Doing this also prevents the forums from parsing bbcoding. Edited September 14, 2005 by cmatcmextra (see edit history) Share this post Link to post Share on other sites
dundun2007 0 Report post Posted September 13, 2005 $formated = preg_replace($regexes, $replacements, $text); You lost me here why do you have to replace the reg in the first place cant you just add a simple image edit to the end to save you the time and trouble of having to update and resend all the information when you go to add a image to the main root? Share this post Link to post Share on other sites
wariorpk 0 Report post Posted September 14, 2005 Nice tutorial I always wondered how to do that. Now if someone comes up with some good html it can be used for their forum. Share this post Link to post Share on other sites
Revolutionary. 0 Report post Posted September 15, 2005 Woah...I've always wondered how BB Code was implemented, that's pretty cool. And yeah, somehow I never knew what preg_replace did...I hadn't even heard about it that much before I read this. Wow, nice tutorial and thanks for the help. Share this post Link to post Share on other sites