Jump to content

BBCode - live on page, regex replace?


PC Nerd

Recommended Posts

Hi,

 

Im looking for an easy way to replace bbCode tags with html.

 

my current setup is:

 

function bb2html(text) {
//bb = new Array("[b]", "[/b]");
//html = new Array("[<b>", "</b>");

text = text.replace("[b]", "<b>");
text = text.replace("[/b]", "</b>");

text = text.replace("[i]", "<i>");
text = text.replace("[/i]", "</i>");

text = text.replace("[u]", "<u>");
text = text.replace("[/u]", "</u>");

text = text.replace("
[left]", "<div style = 'text-align: left;'>");
text = text.replace("[/left]
", "</span>");

text = text.replace("
[center]", "<div style = 'text-align: center;'>");
text = text.replace("[/center]
", "</span>");

text = text.replace("
[right]", "<div style = 'text-align: right;'>");
text = text.replace("[/right]
", "</span>");

text = text.replace("[u]", "<u>");
text = text.replace("[/u]", "</u>");

return text;
}

 

 

however as soon as i get tags such as "text" - that sort of code wont work.

 

I beleive ill hav eot use regex to match the [color= part, but then how can i save the hexidecimal code?

 

Thanks

 

NOTE:

the text value passed to the function is along the lines of:

text = "This is some text More text";

 

 

Link to comment
Share on other sites

ok - ive realised that the text i passed at teh end and after the code has accidently been executed as bbcode for the forum:

 

[*COLOR*=*ff00ff*] Text [*/*COLOR*]

 

ignore the "*" for the value passed etc.

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.