Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Replacing tags

  1. #1
    Regular Coder
    Join Date
    Apr 2006
    Posts
    133
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Replacing tags

    Hi everybody,

    I would like to know how I can separate a special tag created by me from an info coming from database. For example:

    if the text is

    This is a test message. This point is the part where we get the [link=default.asp]link[/link]

    How can I replace [link=default.asp] tag with <a href="default.asp"> tag???

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    The sunny side of the Alps
    Posts
    230
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    sText = "This is a test message. This point is the part where we get the [link=default.asp]link[/link]"
    sText = Replace(sText,"[link=default.asp]","<a href=""default.asp"">")
    sText = Replace(sText,"[/link]","</a>")

  • #3
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Also look into bbcode scripts as they will give you an idea of using regex to parse the text into links.


    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
    
    
    '----------------------------------------
    ' Turn BBcode into HTML
    '----------------------------------------
    Function BBCodeToHTML(strString)
    	strString = ReplaceRegExp(strString, "\[link=([^\]]*)\]([^\[]*)\[/link\]", "<a href=""$1"">$2</a>")
    	BBCodeToHTML = strString
    End Function
    
    str = "hello there this is a [link=default.asp]link[/link]"
    Response.Write BBCodeToHTML(str)
    %>
    http://forums.aspfree.com/code-bank-...ipt-90019.html


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •