Hi,
Apologies if this has been posted before. I used the search and couldn't seem to find anything.
Is there already a pre-built function or class in PHP that will parse HTML code generated by FCKEditor and fix bugs? For example, remove stupid formatting (e.g. <font> tags), etc.
I use FCKEditor for my CMS's to edit content areas of pages. These generally only include headings, paragraphs, lists, images, etc. FCKEditor a lot of the time throws in code that is not needed and generally screws up our clean code. For example, <font> tags, classes, styles, etc.
I need a function or class written in PHP to parse the code from FCKEditor to remove things not needed.
If there isn't one, fair enough, I will just write one myself. I'm just hoping one already exists!
Thank you.
Apologies if this has been posted before. I used the search and couldn't seem to find anything.
Is there already a pre-built function or class in PHP that will parse HTML code generated by FCKEditor and fix bugs? For example, remove stupid formatting (e.g. <font> tags), etc.
I use FCKEditor for my CMS's to edit content areas of pages. These generally only include headings, paragraphs, lists, images, etc. FCKEditor a lot of the time throws in code that is not needed and generally screws up our clean code. For example, <font> tags, classes, styles, etc.
I need a function or class written in PHP to parse the code from FCKEditor to remove things not needed.
If there isn't one, fair enough, I will just write one myself. I'm just hoping one already exists!
Thank you.
Re: HTML Clean UP in PHP?
Re: HTML Clean UP in PHP?
As much as I keep on telling her to type it in directly she refuses. She won't even use the Paste from Word option.
Looks like I'll write my own! I'll post it here when I do it next week.
Re: HTML Clean UP in PHP?
How about this little program?
I haven't used it but even W3C recommends it for cleaning up pages with <font> tags.
Re: HTML Clean UP in PHP?
Re: HTML Clean UP in PHP?
dont use above. use http://htmlpurifier.org/
anti xss, own tidy, validator
Re: HTML Clean UP in PHP?
Re: HTML Clean UP in PHP?
Yes, of course. Simplify adjust the HTML.Allowed configuration in HTML Purifier and only allow HTML tags and attributes you want. (Disclaimer: I wrote HTML Purifier)
Re: HTML Clean UP in PHP?
Have a look at htmLawed, a highly customizable, 45 kb, single file PHP script to filter/purify HTML. Besides restricting tags/elements, attributes and URL protocols as per your specification, and balancing HTML tags and ensuring valid tag nesting/well-formedness, it also has good anti-XSS and anti-spam measures.
Re: HTML Clean UP in PHP?
Yes, HTML tidy which has a PHP interface, if your server supports it.
http://www.php.net/tidy
with lots of options as defined at:
http://tidy.sourceforge.net/docs/quickref.html
Something like this should work:
<?php
// Before this point, we have $html coming out of FCKeditor or anywhere else as an HTML string
# Tidy up if tidy is installed
if (function_exists ('tidy_parse_string')) {
# Set options - see http://tidy.sourceforge.net/docs/quickref.html
$parameters = array (
'clean' => true,
'drop-proprietary-attributes' => true,
'drop-font-tags' => true,
'drop-empty-paras' => true,
'enclose-text' => true,
'fix-backslash' => false,
'force-output' => true,
'hide-comments' => true,
'indent' => false,
'indent-spaces' => 4,
'join-classes' => true,
'join-styles' => true,
'logical-emphasis' => true,
'output-xhtml' => true,
'merge-divs' => true,
'show-body-only' => true,
'word-2000' => true,
'wrap' => 0,
);
# Do the cleaning of $content
$content = tidy_parse_string ($html, $parameters);
tidy_clean_repair ($html);
$content = tidy_get_output ($html);
}
?>