Parse/strip/replace bad MS Word characters

Posted on 2006-05-24
Last Modified: 2008-01-09
I have a friend who I wrote some very simple publishing software,
basically he takes his writtings and puts them online.  Well his
writtings are in Word and so he has alot of special characters that he
inputs, some unknowingly, into the database.  Are there any classes or
samples of what others have done to strip/replace/find these special
characters, I have asked him to be careful, but he will do it once or
twice and then forget and lapse, and I get a call saying can you help
me get these out.

Any ideas?
Question by:iceman19330
    LVL 33

    Expert Comment

    If you know what particular characters he uses and what you'd like them to be, you can use the strtr function.
    Otherwise, you can use either ereg_replace or preg_replace to strip anything that isn't allowed.

    Author Comment

    Thats my problem is that in Word they look like one thing in the db they look like another, and I tried parsing the script and it couldnt pick them up.  So I was looking to see if someone knew about what the charaters would look like to the script.  The ones that I know are an issue are ` and the fancy double quotes.
    LVL 33

    Expert Comment

    You can use the ord() function to find out the ASCII value of the special characters.

    Look in the user comments on that page; somebody has already written some functions with this particular problem in mind.
    LVL 49

    Accepted Solution

    What i noticed that sometimes might work is to use:

    echo htmlentities(utf8_decode($stringFromDatabase));

    LVL 20

    Expert Comment

    by:Muhammad Wasif
    While pasting word document to textarea or whatever you have, use javascripts function getData(). It work only with IE.
    var content = clipboardData.getData("Text");

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Easy Project Management (No User Manual Required)

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    As this topic comes over and over again in different forms, I've finally decided to write a short (yea, right...) article / tutorial about pagination with PHP with MySQL database. There are dozens of these kind of tutorials, I know - I wanted to mak…
    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now