Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Ultimate Bbcode Tutorial, [b ],[ i],[u],[quote ],[img ],smilies
scheme
post Aug 13 2005, 05:35 AM
Post #1


Newbie
*

Group: Members
Posts: 2
Joined: 13-August 05
Member No.: 10,646



THIS BBCODE TUTORIAL was found to be copied.

-- TUTORIAL EDITED --

This post has been edited by OpaQue: Sep 17 2005, 11:38 AM
Go to the top of the page
 
+Quote Post
karlo
post Aug 13 2005, 09:25 AM
Post #2


Privileged Member
*********

Group: Members
Posts: 618
Joined: 30-October 04
From: Philippines
Member No.: 2,049



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! smile.gif
Go to the top of the page
 
+Quote Post
scheme
post Aug 13 2005, 02:13 PM
Post #3


Newbie
*

Group: Members
Posts: 2
Joined: 13-August 05
Member No.: 10,646



I'm not really sure what you mean exactly, but the regex have to be designed before the preg_replace() call
Go to the top of the page
 
+Quote Post
beeseven
post Aug 13 2005, 05:03 PM
Post #4


Privileged Member
*********

Group: Members
Posts: 629
Joined: 26-February 05
Member No.: 3,995



Very nice, I always wondered what the stuff in preg_replace meant.
Go to the top of the page
 
+Quote Post
MXBrandon
post Sep 13 2005, 12:32 AM
Post #5


Newbie
*

Group: Members
Posts: 2
Joined: 13-September 05
Member No.: 11,800



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"
"/\[url=(?:http:\/\/)?([\/0-9a-zA-Z._-]+)\]([\D\S]+?)\[\/url\]/i"
"/\[img\]([\D\S]+?)\[\/img\]/i"
);
Go to the top of the page
 
+Quote Post
thablkpanda
post Sep 13 2005, 12:35 AM
Post #6


Super Member
*********

Group: Members
Posts: 339
Joined: 2-December 04
From: Atlanta, GA
Member No.: 2,516



Excellent work. Good for people trying to make their own CMS'es/Forums/etc, straight out the ground with PHP.

Panda
Go to the top of the page
 
+Quote Post
MXBrandon
post Sep 13 2005, 10:10 PM
Post #7


Newbie
*

Group: Members
Posts: 2
Joined: 13-September 05
Member No.: 11,800



Is there a way make nested codes work? For example, using the code provided above, if someone types in this:

CODE
[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:

CODE
<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.


This post has been edited by cmatcmextra: Sep 14 2005, 05:49 PM
Go to the top of the page
 
+Quote Post
dundun2007
post Sep 13 2005, 10:17 PM
Post #8


Super Member
*********

Group: Members
Posts: 475
Joined: 22-August 04
Member No.: 877



CODE
$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?
Go to the top of the page
 
+Quote Post
wariorpk
post Sep 14 2005, 07:43 PM
Post #9


Privileged Member
*********

Group: Members
Posts: 661
Joined: 18-April 05
Member No.: 5,852



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.
Go to the top of the page
 
+Quote Post
Revolutionary.
post Sep 15 2005, 01:39 AM
Post #10


Member [Level 1]
****

Group: Members
Posts: 53
Joined: 25-July 05
From: New York.
Member No.: 9,849



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.