Replacing a special character
Replacing a special character
am 18.04.2010 14:59:33 von Michael Stroh
I have this form that people use to add entries into a MySQL database. =
Recently I've had some users insert â=92 in their entries instead =
of - which is causing some issues with scripts down the line. I'd like =
to replace the â=92 character with -.
Originally I had something like=20
$name =3D mysql_escape_string($_POST["name"]);=20
which would convert the offending character to − before entering =
it into the database. It's this encoding that is causing the problems =
since some scripts send out emails with this entry in their subject line =
which looks messy.
I've tried adding the following line after the previous line to help fix =
this issue, however, I just got another entry with the same problem.
preg_replace('/−/','-',$name);
Any suggestions on how others would fix this problem? I'd just like to =
fix it before the entry hits the database instead of creating fixes on =
the other end of things.
Cheers,
Michael=
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Replacing a special character
am 18.04.2010 16:40:42 von Phpster
On Apr 18, 2010, at 8:59 AM, Michael Stroh wrote:
> I have this form that people use to add entries into a MySQL =20
> database. Recently I've had some users insert â=92 in their =
entries ins=20
> tead of - which is causing some issues with scripts down the line. I=20=
> 'd like to replace the â=92 character with -.
>
> Originally I had something like
>
> $name =3D mysql_escape_string($_POST["name"]);
>
> which would convert the offending character to − before =20
> entering it into the database. It's this encoding that is causing =20
> the problems since some scripts send out emails with this entry in =20
> their subject line which looks messy.
>
> I've tried adding the following line after the previous line to help =20=
> fix this issue, however, I just got another entry with the same =20
> problem.
>
> preg_replace('/−/','-',$name);
>
> Any suggestions on how others would fix this problem? I'd just like =20=
> to fix it before the entry hits the database instead of creating =20
> fixes on the other end of things.
>
>
> Cheers,
> Michael
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
One option is to send an HTML email which would have the email reader =20=
interpret that code correctly
Bastien=
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Replacing a special character
am 18.04.2010 16:46:20 von Peter Lind
On 18 April 2010 16:40, Phpster wrote:
>
>
> On Apr 18, 2010, at 8:59 AM, Michael Stroh wrote:
>
>> I have this form that people use to add entries into a MySQL database.
>> Recently I've had some users insert â=92 in their entries instead o=
f - which is
>> causing some issues with scripts down the line. I'd like to replace the =
â=92
>> character with -.
>>
>> Originally I had something like
>>
>> $name =3D mysql_escape_string($_POST["name"]);
>>
>> which would convert the offending character to − before entering i=
t
>> into the database. It's this encoding that is causing the problems since
>> some scripts send out emails with this entry in their subject line which
>> looks messy.
>>
>> I've tried adding the following line after the previous line to help fix
>> this issue, however, I just got another entry with the same problem.
>>
>> preg_replace('/−/','-',$name);
>>
>> Any suggestions on how others would fix this problem? I'd just like to f=
ix
>> it before the entry hits the database instead of creating fixes on the o=
ther
>> end of things.
>>
>>
>> Cheers,
>> Michael
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>
> One option is to send an HTML email which would have the email reader
> interpret that code correctly
>
> Bastien
Another option would be to use mysql_real_escape_string and make sure
that your code and the database are using utf-8. Then when the email
is sent, make sure that uses utf-8 as well.
Regards
Peter
--=20
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Replacing a special character
am 18.04.2010 19:08:48 von Michiel Sikma
--0016e6d588b9d39916048485e542
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On 18 April 2010 16:46, Peter Lind wrote:
> On 18 April 2010 16:40, Phpster wrote:
> >
> >
> > On Apr 18, 2010, at 8:59 AM, Michael Stroh wrote:
> >
> >> I have this form that people use to add entries into a MySQL database.
> >> Recently I've had some users insert â=92 in their entries instead=
of -
> which is
> >> causing some issues with scripts down the line. I'd like to replace th=
e
> â=92
> >> character with -.
> >>
> >> Originally I had something like
> >>
> >> $name =3D mysql_escape_string($_POST["name"]);
> >>
> >> which would convert the offending character to − before entering
> it
> >> into the database. It's this encoding that is causing the problems sin=
ce
> >> some scripts send out emails with this entry in their subject line whi=
ch
> >> looks messy.
> >>
> >> I've tried adding the following line after the previous line to help f=
ix
> >> this issue, however, I just got another entry with the same problem.
> >>
> >> preg_replace('/−/','-',$name);
> >>
> >> Any suggestions on how others would fix this problem? I'd just like to
> fix
> >> it before the entry hits the database instead of creating fixes on the
> other
> >> end of things.
> >>
> >>
> >> Cheers,
> >> Michael
> >> --
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >
> > One option is to send an HTML email which would have the email reader
> > interpret that code correctly
> >
> > Bastien
>
> Another option would be to use mysql_real_escape_string and make sure
> that your code and the database are using utf-8. Then when the email
> is sent, make sure that uses utf-8 as well.
>
> Regards
> Peter
>
>
Make sure the database connection is also utf8:
set names 'utf8';
Typically, you should keep everything in utf8 unless you have a very good
reason not to.
And as Peter mentioned, the proper way to escape MySQL inserts (that is, if
you're not already using a framework that does this competently) is
mysql_real_escape_string().
Michiel
--0016e6d588b9d39916048485e542--
Re: Replacing a special character
am 18.04.2010 20:38:23 von Michael Stroh
Thanks for the advice. I've changed the code to use =
mysql_real_escape_string. So now it is
$name =3D mysql_real_escape_string($name);
preg_replace('/−/','-',$name);
but it's still not replacing the − string. I've also changed the =
field in the database so that now it is using the collation =
utf8_general_ci. I've also tried
preg_replace('/â=92/','-',$name);
$name =3D mysql_real_escape_string($name);
preg_replace('/−/','-',$name);
and that also did not work. Any ideas?
Michael
On Apr 18, 2010, at 1:08 PM, Michiel Sikma wrote:
> On 18 April 2010 16:46, Peter Lind wrote:
>=20
>> On 18 April 2010 16:40, Phpster wrote:
>>>=20
>>>=20
>>> On Apr 18, 2010, at 8:59 AM, Michael Stroh wrote:
>>>=20
>>>> I have this form that people use to add entries into a MySQL =
database.
>>>> Recently I've had some users insert â=92 in their entries =
instead of -
>> which is
>>>> causing some issues with scripts down the line. I'd like to replace =
the
>> â=92
>>>> character with -.
>>>>=20
>>>> Originally I had something like
>>>>=20
>>>> $name =3D mysql_escape_string($_POST["name"]);
>>>>=20
>>>> which would convert the offending character to − before =
entering
>> it
>>>> into the database. It's this encoding that is causing the problems =
since
>>>> some scripts send out emails with this entry in their subject line =
which
>>>> looks messy.
>>>>=20
>>>> I've tried adding the following line after the previous line to =
help fix
>>>> this issue, however, I just got another entry with the same =
problem.
>>>>=20
>>>> preg_replace('/−/','-',$name);
>>>>=20
>>>> Any suggestions on how others would fix this problem? I'd just like =
to
>> fix
>>>> it before the entry hits the database instead of creating fixes on =
the
>> other
>>>> end of things.
>>>>=20
>>>>=20
>>>> Cheers,
>>>> Michael
>>>> --
>>>> PHP General Mailing List (http://www.php.net/)
>>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>>=20
>>>=20
>>> One option is to send an HTML email which would have the email =
reader
>>> interpret that code correctly
>>>=20
>>> Bastien
>>=20
>> Another option would be to use mysql_real_escape_string and make sure
>> that your code and the database are using utf-8. Then when the email
>> is sent, make sure that uses utf-8 as well.
>>=20
>> Regards
>> Peter
>>=20
>>=20
> Make sure the database connection is also utf8:
>=20
> set names 'utf8';
>=20
> Typically, you should keep everything in utf8 unless you have a very =
good
> reason not to.
> And as Peter mentioned, the proper way to escape MySQL inserts (that =
is, if
> you're not already using a framework that does this competently) is
> mysql_real_escape_string().
>=20
> Michiel
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Replacing a special character
am 18.04.2010 20:44:46 von Mari Masuda
Maybe you could try to assign the return value of preg_replace to a =
variable so you can use it later, like:=20
$name =3D preg_replace('/−/','-',$name);
On Apr 18, 2010, at 11:38 AM, Michael Stroh wrote:
> Thanks for the advice. I've changed the code to use =
mysql_real_escape_string. So now it is
>=20
> $name =3D mysql_real_escape_string($name);
> preg_replace('/−/','-',$name);
>=20
> but it's still not replacing the − string. I've also changed the =
field in the database so that now it is using the collation =
utf8_general_ci. I've also tried
>=20
> preg_replace('/â=92/','-',$name);
> $name =3D mysql_real_escape_string($name);
> preg_replace('/−/','-',$name);
>=20
> and that also did not work. Any ideas?
>=20
> Michael
>=20
>=20
>=20
> On Apr 18, 2010, at 1:08 PM, Michiel Sikma wrote:
>=20
>> On 18 April 2010 16:46, Peter Lind wrote:
>>=20
>>> On 18 April 2010 16:40, Phpster wrote:
>>>>=20
>>>>=20
>>>> On Apr 18, 2010, at 8:59 AM, Michael Stroh =
wrote:
>>>>=20
>>>>> I have this form that people use to add entries into a MySQL =
database.
>>>>> Recently I've had some users insert â=92 in their entries =
instead of -
>>> which is
>>>>> causing some issues with scripts down the line. I'd like to =
replace the
>>> â=92
>>>>> character with -.
>>>>>=20
>>>>> Originally I had something like
>>>>>=20
>>>>> $name =3D mysql_escape_string($_POST["name"]);
>>>>>=20
>>>>> which would convert the offending character to − before =
entering
>>> it
>>>>> into the database. It's this encoding that is causing the problems =
since
>>>>> some scripts send out emails with this entry in their subject line =
which
>>>>> looks messy.
>>>>>=20
>>>>> I've tried adding the following line after the previous line to =
help fix
>>>>> this issue, however, I just got another entry with the same =
problem.
>>>>>=20
>>>>> preg_replace('/−/','-',$name);
>>>>>=20
>>>>> Any suggestions on how others would fix this problem? I'd just =
like to
>>> fix
>>>>> it before the entry hits the database instead of creating fixes on =
the
>>> other
>>>>> end of things.
>>>>>=20
>>>>>=20
>>>>> Cheers,
>>>>> Michael
>>>>> --
>>>>> PHP General Mailing List (http://www.php.net/)
>>>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>>>=20
>>>>=20
>>>> One option is to send an HTML email which would have the email =
reader
>>>> interpret that code correctly
>>>>=20
>>>> Bastien
>>>=20
>>> Another option would be to use mysql_real_escape_string and make =
sure
>>> that your code and the database are using utf-8. Then when the email
>>> is sent, make sure that uses utf-8 as well.
>>>=20
>>> Regards
>>> Peter
>>>=20
>>>=20
>> Make sure the database connection is also utf8:
>>=20
>> set names 'utf8';
>>=20
>> Typically, you should keep everything in utf8 unless you have a very =
good
>> reason not to.
>> And as Peter mentioned, the proper way to escape MySQL inserts (that =
is, if
>> you're not already using a framework that does this competently) is
>> mysql_real_escape_string().
>>=20
>> Michiel
>=20
>=20
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>=20
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Replacing a special character
am 18.04.2010 20:53:59 von Michael Stroh
That did it! Thanks!
Michael
On Apr 18, 2010, at 2:44 PM, Mari Masuda wrote:
> Maybe you could try to assign the return value of preg_replace to a =
variable so you can use it later, like:=20
>=20
> $name =3D preg_replace('/−/','-',$name);
>=20
>=20
> On Apr 18, 2010, at 11:38 AM, Michael Stroh wrote:
>=20
>> Thanks for the advice. I've changed the code to use =
mysql_real_escape_string. So now it is
>>=20
>> $name =3D mysql_real_escape_string($name);
>> preg_replace('/−/','-',$name);
>>=20
>> but it's still not replacing the − string. I've also changed =
the field in the database so that now it is using the collation =
utf8_general_ci. I've also tried
>>=20
>> preg_replace('/â=92/','-',$name);
>> $name =3D mysql_real_escape_string($name);
>> preg_replace('/−/','-',$name);
>>=20
>> and that also did not work. Any ideas?
>>=20
>> Michael
>>=20
>>=20
>>=20
>> On Apr 18, 2010, at 1:08 PM, Michiel Sikma wrote:
>>=20
>>> On 18 April 2010 16:46, Peter Lind wrote:
>>>=20
>>>> On 18 April 2010 16:40, Phpster wrote:
>>>>>=20
>>>>>=20
>>>>> On Apr 18, 2010, at 8:59 AM, Michael Stroh =
wrote:
>>>>>=20
>>>>>> I have this form that people use to add entries into a MySQL =
database.
>>>>>> Recently I've had some users insert â=92 in their entries =
instead of -
>>>> which is
>>>>>> causing some issues with scripts down the line. I'd like to =
replace the
>>>> â=92
>>>>>> character with -.
>>>>>>=20
>>>>>> Originally I had something like
>>>>>>=20
>>>>>> $name =3D mysql_escape_string($_POST["name"]);
>>>>>>=20
>>>>>> which would convert the offending character to − before =
entering
>>>> it
>>>>>> into the database. It's this encoding that is causing the =
problems since
>>>>>> some scripts send out emails with this entry in their subject =
line which
>>>>>> looks messy.
>>>>>>=20
>>>>>> I've tried adding the following line after the previous line to =
help fix
>>>>>> this issue, however, I just got another entry with the same =
problem.
>>>>>>=20
>>>>>> preg_replace('/−/','-',$name);
>>>>>>=20
>>>>>> Any suggestions on how others would fix this problem? I'd just =
like to
>>>> fix
>>>>>> it before the entry hits the database instead of creating fixes =
on the
>>>> other
>>>>>> end of things.
>>>>>>=20
>>>>>>=20
>>>>>> Cheers,
>>>>>> Michael
>>>>>> --
>>>>>> PHP General Mailing List (http://www.php.net/)
>>>>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>>>>=20
>>>>>=20
>>>>> One option is to send an HTML email which would have the email =
reader
>>>>> interpret that code correctly
>>>>>=20
>>>>> Bastien
>>>>=20
>>>> Another option would be to use mysql_real_escape_string and make =
sure
>>>> that your code and the database are using utf-8. Then when the =
email
>>>> is sent, make sure that uses utf-8 as well.
>>>>=20
>>>> Regards
>>>> Peter
>>>>=20
>>>>=20
>>> Make sure the database connection is also utf8:
>>>=20
>>> set names 'utf8';
>>>=20
>>> Typically, you should keep everything in utf8 unless you have a very =
good
>>> reason not to.
>>> And as Peter mentioned, the proper way to escape MySQL inserts (that =
is, if
>>> you're not already using a framework that does this competently) is
>>> mysql_real_escape_string().
>>>=20
>>> Michiel
>>=20
>>=20
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>=20
>=20
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php