#1
  1. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jan 2014
    Posts
    69
    Rep Power
    5

    BBCode to HTML funtion help


    Hi guys

    I'm currently working on a function that will convert BBCode into HTML tags.

    It almost works perfectly but for some reason it's unable to handle nested tags (ie tags within another set of tags).

    For example, I submit the following BBCode:

    Here is my description

    but the output on my page is:

    Code:
    <center><span style="font-weight: bold;"><span style="text-decoration: underline;"><span style=" font-style: italic;">Here is my description</span></span></span></center>
    It just can't handle the [color=#ff3333] tags being nested within other tags.

    My code can be seen below

    Is there any way of rectifying this issue? I have been on this for about 5 days now and can't figure it out. Any help would be much appreciated

    Best regards

    Rod from the UK


    Code:
    <%
    
    '----------------------------------------
    ' Common Regular Expression Function
    '----------------------------------------
    Function ReplaceRegExp(strString, strPattern, strReplace)
    
    	Dim RE: Set RE = New RegExp
    
    	With RE
    		.Pattern = strPattern
    		.Global = True
    		ReplaceRegExp = .Replace(strString, strReplace)
    	End With
    	
    End Function
    
    'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    
    '----------------------------------------
    ' Turn BBcode into HTML
    '----------------------------------------
    Function BBCodeToHTML(strString)
    	strString = ReplaceRegExp(strString, "(http|ftp|https)(:\/\/[\w\-_]+)((\.[\w\-_]+)+)([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?", "<a href=""$1$2$3$5"" target=""_blank"">$1$2$3$5</a>")
    	strString = ReplaceRegExp(strString, "\[color=([^\]]*)\]([^\[]*)\[/color\]", "<span style=""color: $1;"">$2</span>")
    	strString = ReplaceRegExp(strString, "\[size=([^\]]*)\]([^\[]*)\[/size\]", "<font size=""$1"">$2</font>")
    	strString = ReplaceRegExp(strString, "\[font=([^\]]*)\]([^\[]*)\[/font\]", "<span style=""font-family: $1, Sans-Serif, Serif;"">$2</span>")
    	strString = ReplaceRegExp(strString, "\[quote=([^\]]*)\]([^\[]*)\[/quote\]", "<div class=""quote""><span style=""font-weight: bold; font-size: 8pt;"">$1 said:</span><pre class=""quote1"">$2</pre></div>")
    
    	strString = Replace(strString, "", "<span style=""font-weight: bold;"">")
    	strString = Replace(strString, "", "<span style=""font-weight: bold;"">")
    	strString = Replace(strString, "", "<span style=""text-decoration: underline;"">")
    	strString = Replace(strString, "", "<span style=""text-decoration: underline;"">")
    	strString = Replace(strString, "", "<span style="" font-style: italic;"">")
    	strString = Replace(strString, "", "<span style="" font-style: italic;"">")
    	strString = Replace(strString, "", "</span>")
    	strString = Replace(strString, "", "</span>")
    	strString = Replace(strString, "", "</span>")
    	strString = Replace(strString, "", "</span>")
    	strString = Replace(strString, "", "</span>")
    	strString = Replace(strString, "", "</span>")
    
    	strString = Replace(strString, "[li]", "<li>")
    	strString = Replace(strString, "[/li]", "</li>")
    
    	strString = Replace(strString, "[ol]", "<ol>")
    	strString = Replace(strString, "[/ol]", "</ol>")
    
    	strString = Replace(strString, "[ul]", "<ul>")
    	strString = Replace(strString, "[/ul]", "</ul>")
    
    	strString = Replace(strString, "
    ", "<center>") strString = Replace(strString, "
    ", "</center>") BBCodeToHTML = strString End Function 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX strTest = "
    Here is my description
    " description = BBCodeToHTML(strTest) %> <%=description%>
    Last edited by rjoseph244510; May 24th, 2016 at 01:36 PM.

Similar Threads

  1. Convert BBCode to HTML
    By rjoseph244510 in forum ASP Development
    Replies: 0
    Last Post: May 18th, 2016, 03:44 PM
  2. If Else funtion in ASP.NET?
    By vbmntv in forum .NET Development
    Replies: 8
    Last Post: April 1st, 2011, 01:34 PM
  3. Funtion to Schedule task
    By dev5 in forum ASP Development
    Replies: 9
    Last Post: July 9th, 2004, 03:30 PM
  4. Unbound Funtion
    By ocbren in forum ASP Development
    Replies: 1
    Last Post: April 19th, 2004, 01:41 PM
  5. Funtion
    By ^devil^ in forum Programming Help
    Replies: 2
    Last Post: April 16th, 2004, 12:21 AM

IMN logo majestic logo threadwatch logo seochat tools logo