Stripping out characters

Discussion in 'Programming' started by wingnut, Sep 28, 2007.

  1. #1
    I currently use FCKeditor to allow users to enter comments, and that info is then stored in our db table.

    I'm having a problem because I want to display some of that data, but FCKeditor adds <p> and </p> characters around the text.

    I'm already using my own <p> where I need them, and need to strip out the characters. I know I can use findnocase() but if the characters are in there multiple times, such as:

    <p>This is just a test</p>
    <p>Let me know how it works</p>

    How can I make sure to remove all instances of both <p> and </p> ??
     
    wingnut, Sep 28, 2007 IP
  2. CerIs

    CerIs Active Member

    Messages:
    69
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    58
    #2
    Just go:

    replacenocase(yourdata,'<p>','','all')
    and
    replacenocase(yourdata,'</p>','','all')
     
    CerIs, Sep 29, 2007 IP
  3. twalters84

    twalters84 Peon

    Messages:
    514
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hey there,

    Allowing uses to write HTML and javascript can be quite dangerous if it is displayed elsewhere on the site - because everything gets inserted.

    It sounds like you are trying to fix certain things that have already been inserted. If you want to fix the root of the problem, you can do something like this:

    <cfif #REFind("<[^>]*>", FORM.USER_TEXT)#>

    You can throw an error message here.

    <cfelse>

    Insert their text into the database.

    </cfif>

    Just set FORM.USER_TEXT to whatever your form field is called.

    Hope this helps.

    Sincerely,
    Travis Walters
     
    twalters84, Sep 29, 2007 IP