PC Nerd Posted July 26, 2008 Share Posted July 26, 2008 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"; Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted July 26, 2008 Author Share Posted July 26, 2008 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.