Hi Kevin,
Thanks for this, it got rid of my special characters. However I now have a 
problem with foreign characters.
'De l'Âge du fer au haut Moyen Âge.' 
gets inserted into oracle as 
De l'Âge du fer au haut Moyen Âge.
I have an oracle procedure that inserts the data, if I run the oracle procedure 
directly in oracle it inserts the special characters okay. The problem seems to 
be with the way php execute the procedure.
Any ideas?


From: Kevin Murphy [mailto:[EMAIL PROTECTED] 
Sent: 16 November 2006 16:45
To: David Skyers
Cc: php-db@lists.php.net
Subject: Re: [PHP-DB] Special Character

A solution I use is to do apply this function to all POST data collected. The 
key here for your problem is the chr(150) and chr(151) that are replaced with a 
normal hyphen. This also takes care of MS Words Smart Quotes. If there are 
other MS Characters you need to convert, just add them to the pattern field as 
the numeric version, and then add one to the array what the replacement is.  

function sanitize($data)
  $pattern = array(chr(145),chr(146),chr(147),chr(148),chr(150),chr(151));
$replacements = array("'","'",'"','"','-','--');
$data = str_replace($pattern,$replacements,$data);
$data = trim($data);
$data = preg_replace("/ +/", " ", $data);
$data = addslashes($data);
return $data;

Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada Community College

On Nov 16, 2006, at 7:32 AM, David Skyers wrote:


        The problem is, we will have hundreds of users using Microsoft Word and
        we cannot switch it off for all of them. Ideally I need some type of
        string replace function, so no matter what they enter it gets trapped an

        It's not the normal hyphens that cause a problem but the long hyphens.



        -----Original Message-----
        From: Dan Shirah [mailto:[EMAIL PROTECTED]
        Sent: 16 November 2006 15:13
        To: php-db@lists.php.net
        Subject: Re: [PHP-DB] Special Character

        To turn off the auto formatting of hyphens:

        In Microsoft Word 2003:

        Open a new document.
        Go to Tools>Auto Correct Options>
        Select the "Auto Format As You Type" tab Deselect the "Hyphens (--) with
        Dash (-)" option.

        Even though it says it will replace a double hyphen (--) with a Dash
        (This is an em dash) it also does the same thing for a single hyphen
        depending on the sentance structure.

        Hope this helps!


        On 11/16/06, Niel Archer <[EMAIL PROTECTED]> wrote:

                Hi David

                What you describe sounds like Word is auto replacing hyphens 
                en- or em-dashes.  This is a configurable option in Word that 
                defaults to on.  Try using double quotes, If they get switched 
to 66's
                and 99's style quotes, then that is likely the problem.  I no 
                use MS Office for these and other reasons, so cannot tell you 
how to
                switch off this formatting.  But it can be switched off, 

        within it.

                The only other option I can think of would be to change your Db
                character set to one that can accept these extended characters. 
                might also mean changing some of Window's/Word's behaviour (to 
                UTF-8 for example).


                PHP Database Mailing List (http://www.php.net/) To unsubscribe, 

Reply via email to