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
https://forums.phpfreaks.com/topic/116698-bbcode-live-on-page-regex-replace/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.