Cleaning up Automated Code

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

Hi, I have kind of a strange request, and with that, I'm stumped to what to even search for. So even if no one has a solutions, a suggestion of what to search for would help. Smiling

We use an RTE for clients (the RTE is set, so a suggestion of using a different one won't work). Anyhow sometimes there is invalid code generated (or when copied and paste) where there is say an opening tag and no closing one. Or if they use the "view source" mode, they can possibly enter an closing tag without the opening, which when rendered by the CMS will now close a div before it should be.

So anyhow, we were wondering if there is code (PHP) that will validate, and possible delete things like this.

Right now I'm looking at going through and making a list of tags the RTE generates, and strip anything else.

So any suggestions as to a solution or even just an idea of what to search for would help.

Thanks.

-Greg

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

If you're looking to remove some HTML tags that the RTE generates, the strip_tags() function will take care of that.

What RTE editor are you using? Most usually give you the option on what kind of formatting to allow.

Another option is to run the HTML through Tidy.

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

Strip tags will eliminate all tags, I need to get rid of mismatched tags

(ie, there is a closing , , etc where there was no opening.)

Not sure as to the original RTE currently being used (which has been tweaked), I know we are changing to TinyMCE in the next version of the CMS. the current one does have a glitch where somehow you can have it add a paragraph and select and delete just right where it will leave the closing in there...

Plus there is the issue that there are some clients with the need to actually copy and paste actual HTML code in, and they could highlight mismatched tags.

This isn't a problem that comes up a lot, it's just when it does (like today) makes me think "how can we stop that" lol.

I'll take a look at Tidy after work today. Thank you for that!

-Greg

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.