Search code examples
phpjavascriptfckeditor

FCKeditor is leaving behind a lot of open tags - how to remove them


So I am using FCKeditor and the problem I am having is that when the user writes the document sometimes info is copied from Word, other times it is written directly in the editor and other times it could be done both ways. What this leaves me with in the DB is a lot of tags that are open and never closed. This is throwing my layout off dramatically and I am trying to find a solution.

I changed the config file to paste as plain text, which I assumed would stop Word formatting from transferring over, and it is still doing it.

So now I am trying to figure out a way to search for the opening tags and delete them before the info is sent to the DB is possible. Or is there some FCKeditor function/config option I am missing to aid me?

Any suggestions on how I should proceed?

Thanks
Levi


Solution

  • Just as a security precaution that will address both security-related problems (like <script> tags being inserted by users, for instance -- which you probably don't want) and presentation-related problems (such as not-closed tags), you could use a tool like HTMLPurifier on your server, on what you are receiving from the browser.

    Of course, this will not solve the first problem, the fact that users can input whatever they want in FCKEditor ; but it will ensure your HTML is both valid and secure.

    Actually, even if FCKEditor wasn't getting you not-valid HTML, you still could use HTMLPurifier, just for security.

    The idea is that you provide a list of :

    • allowed tags
    • allowed attributes to those tags

    And, in return, HTMLPurifier gives you clean and valid HTML.