|PHP to clean-up pasted Microsoft input||#1|
I have a site where users can post stuff (as in forums, comments, etc) using a customised implementation of TinyMCE. A lot of them like to copy & paste from Word, which means their input often comes with a plethora of associated MS inline formatting.
I can't just get rid of
as TinyMCE relies on the span tag for some of it's formatting, and I can't (and don't want to) force said users to use TinyMCE's "Paste From Word" feature (which doesn't seem to work that well anyway).
Anyone know of a library/class/function that would take care of this for me? It must be a common problem, though I can't find anything definitive. I've been thinking recently that a series of brute-force regexes looking for MS-specific patterns might do the trick, but I don't want to re-write something that may already be available unless I must.
Also, fixing of curly quotes, em-dashes, etc would be good. I have my own stuff to do this now, but I'd really just like to find one MS-conversion filter to rule them all.
posted date: 2008-12-18 13:25:00
|Re: PHP to clean-up pasted Microsoft input||#3|
HTML Purifier will create standards compliant markup and filter out many possible attacks (such as XSS).For faster cleanups that don't require XSS filtering, I use the PECL extension Tidy which is a binding for the Tidy HTML utility.If those don't help you, I suggest you switch to FCKEditor which has this feature built-in.
posted date: 2008-12-18 13:39:00
|Re: PHP to clean-up pasted Microsoft input||#4|
Thanks, but neither of those appear to cope with MS formatting, which is what I'm primarily interested in. HTML Purifier has it planned for version 3.5 but with "research necessary".
posted date: 2008-12-18 13:48:00
|Re: PHP to clean-up pasted Microsoft input||#5|
Then I suggest you switch to fckeditor which can deal with word input. Updated my answer.
posted date: 2008-12-18 15:02:00
|Re: PHP to clean-up pasted Microsoft input||#6|
Hmm. I previously preferred TinyMCE over FCKeditor for a number of other reasons, but this may sway me. Thanks for the tip & pleased to be accepting my +1 :)
posted date: 2008-12-18 15:19:00
|Re: PHP to clean-up pasted Microsoft input||#7|
Mind you, (if I switch) I still need to clean all the crap that's already been posted...
posted date: 2008-12-18 15:21:00
|Re: PHP to clean-up pasted Microsoft input||#8|
Also note that FCKEditor is no longer supported and will have problems with modern browsers, so you should use CKEditor instead. ckeditor.com
posted date: 2012-03-20 03:50:00
|Re: PHP to clean-up pasted Microsoft input||#9|
The website http://word2cleanhtml.com/ does a good job on converting from Word. I'm using it in PHP by scrapping, to process some legacy HTML, and until now it's working pretty fine (the result is very clean
code). Of course, being an external service it's not good to use it in online processing like your case.If you try it and it brings many 400 errors, try filtering the HTML with Tidy first.
posted date: 2015-02-12 02:25:00
|select page: « 1 »|