Development PHP: Remove MS Word formatting from HTML

Discussion in 'Software' started by jezmck, 12 Feb 2007.

  1. jezmck

    jezmck Minimodder

    Joined:
    25 Sep 2003
    Posts:
    4,456
    Likes Received:
    36
    I am using FCKEditor in a bespoke CMS.
    The users are insistent on copy/pasting from Word, and won't use the built in Paste-from-Word feature.

    So I thought I could simply remove the <span> and <font> tags from the saved HTML before displaying it.

    I have been trying the strip_selected_tags() function at http://uk.php.net/strip-tags but this often seems to completely remove all traces of the article, rather than just removing the offending tags.

    I can only safely remove <font> tags, and hopefully <span> tags, and need to leave all other formatting.

    Any ideas?
     
  2. DougEdey

    DougEdey I pwn all your storage

    Joined:
    5 Jul 2005
    Posts:
    13,933
    Likes Received:
    33
    why not do some form of reading in each line, then using str_replace to remove the tags?

    ugly though...
     
  3. jezmck

    jezmck Minimodder

    Joined:
    25 Sep 2003
    Posts:
    4,456
    Likes Received:
    36
    it looks like that's the basic idea behind the function on the above-linked page, but perhaps there's a bug in it.

    I'm hoping that someone here will have a brainwave, and think of another way to remove the nasty tags.

    PS - christmas av still?!
     
  4. Jamie

    Jamie ex-Bit-Tech code junkie

    Joined:
    12 Mar 2001
    Posts:
    8,180
    Likes Received:
    54
    regular expression replace?
     
  5. DougEdey

    DougEdey I pwn all your storage

    Joined:
    5 Jul 2005
    Posts:
    13,933
    Likes Received:
    33

    I found a new one yesterday, been too lazy to upload it.
     
  6. RTT

    RTT #parp

    Joined:
    12 Mar 2001
    Posts:
    14,120
    Likes Received:
    74
    I came here to post this :dremel:
     
  7. [Jonny]

    [Jonny] What's a Dremel?

    Joined:
    1 Sep 2003
    Posts:
    296
    Likes Received:
    0
    You could run it through tidy if you have it installed.
     

Share This Page