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
www.wncc.edu
775-445-3326
On Nov 16, 2006, at 7:32 AM, David Skyers wrote:
Thanks,
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
replaced.
It's not the normal hyphens that cause a problem but the long hyphens.
Regards
David
-----Original Message-----
From: Dan Shirah [mailto:mrsquash2@xxxxxxxxx]
Sent: 16 November 2006 15:13
To: php-db@xxxxxxxxxxxxx
Subject: Re: 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!
Dan
On 11/16/06, Niel Archer <niel@xxxxxxxxxxxxx> wrote:
Hi David
What you describe sounds like Word is auto replacing hyphens with
either
en- or em-dashes. This is a configurable option in Word that often
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 longer
use MS Office for these and other reasons, so cannot tell you how to
switch off this formatting. But it can be switched off, somewhere
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. That
might also mean changing some of Window's/Word's behaviour (to be
using
UTF-8 for example).
Niel
--
PHP Database Mailing List (http://www.php.net/) To unsubscribe,
visit:
http://www.php.net/unsub.php