Replacing a special character

I have this form that people use to add entries into a MySQL database. =
Recently I've had some users insert =E2=88=92 in their entries instead =
of - which is causing some issues with scripts down the line. I'd like =
to replace the =E2=88=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 =
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
Michael Stroh [ So, 18 April 2010 14:59 ] [ ID #2039292 ]

Re: Replacing a special character

On Apr 18, 2010, at 8:59 AM, Michael Stroh <stroh [at] astroh.org> wrote:

> I have this form that people use to add entries into a MySQL
> database. Recently I've had some users insert =E2=88=92 in their =
entries ins
> tead of - which is causing some issues with scripts down the line. I =

> 'd like to replace the =E2=88=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 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
>

One option is to send an HTML email which would have the email reader =

interpret that code correctly

Bastien=

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Phpster [ So, 18 April 2010 16:40 ] [ ID #2039296 ]

Re: Replacing a special character

On 18 April 2010 16:40, Phpster <phpster [at] gmail.com> wrote:
>
>
> On Apr 18, 2010, at 8:59 AM, Michael Stroh <stroh [at] astroh.org> wrote:
>
>> I have this form that people use to add entries into a MySQL database.
>> Recently I've had some users insert =E2=88=92 in their entries instead o=
f - which is
>> causing some issues with scripts down the line. I'd like to replace the =
=E2=88=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

--
<hype>
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
</hype>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Peter Lind [ So, 18 April 2010 16:46 ] [ ID #2039297 ]

Re: Replacing a special character

--0016e6d588b9d39916048485e542
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On 18 April 2010 16:46, Peter Lind <peter.e.lind [at] gmail.com> wrote:

> On 18 April 2010 16:40, Phpster <phpster [at] gmail.com> wrote:
> >
> >
> > On Apr 18, 2010, at 8:59 AM, Michael Stroh <stroh [at] astroh.org> wrote:
> >
> >> I have this form that people use to add entries into a MySQL database.
> >> Recently I've had some users insert =E2=88=92 in their entries instead=
of -
> which is
> >> causing some issues with scripts down the line. I'd like to replace th=
e
> =E2=88=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--
Michiel Sikma [ So, 18 April 2010 19:08 ] [ ID #2039302 ]

Re: Replacing a special character

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('/=E2=88=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 <peter.e.lind [at] gmail.com> wrote:
>
>> On 18 April 2010 16:40, Phpster <phpster [at] gmail.com> wrote:
>>>
>>>
>>> On Apr 18, 2010, at 8:59 AM, Michael Stroh <stroh [at] astroh.org> wrote:
>>>
>>>> I have this form that people use to add entries into a MySQL =
database.
>>>> Recently I've had some users insert =E2=88=92 in their entries =
instead of -
>> which is
>>>> causing some issues with scripts down the line. I'd like to replace =
the
>> =E2=88=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 =
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
>>>>
>>>
>>> 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


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Michael Stroh [ So, 18 April 2010 20:38 ] [ ID #2039306 ]

Re: Replacing a special character

Maybe you could try to assign the return value of preg_replace to a =
variable so you can use it later, like:

$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
>
> $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('/=E2=88=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 <peter.e.lind [at] gmail.com> wrote:
>>
>>> On 18 April 2010 16:40, Phpster <phpster [at] gmail.com> wrote:
>>>>
>>>>
>>>> On Apr 18, 2010, at 8:59 AM, Michael Stroh <stroh [at] astroh.org> =
wrote:
>>>>
>>>>> I have this form that people use to add entries into a MySQL =
database.
>>>>> Recently I've had some users insert =E2=88=92 in their entries =
instead of -
>>> which is
>>>>> causing some issues with scripts down the line. I'd like to =
replace the
>>> =E2=88=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 =
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
>>>>>
>>>>
>>>> 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
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Mari Masuda [ So, 18 April 2010 20:44 ] [ ID #2039307 ]

Re: Replacing a special character

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:
>
> $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
>>
>> $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('/=E2=88=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 <peter.e.lind [at] gmail.com> wrote:
>>>
>>>> On 18 April 2010 16:40, Phpster <phpster [at] gmail.com> wrote:
>>>>>
>>>>>
>>>>> On Apr 18, 2010, at 8:59 AM, Michael Stroh <stroh [at] astroh.org> =
wrote:
>>>>>
>>>>>> I have this form that people use to add entries into a MySQL =
database.
>>>>>> Recently I've had some users insert =E2=88=92 in their entries =
instead of -
>>>> which is
>>>>>> causing some issues with scripts down the line. I'd like to =
replace the
>>>> =E2=88=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 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
>>>>>>
>>>>>
>>>>> 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
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Michael Stroh [ So, 18 April 2010 20:53 ] [ ID #2039308 ]
PHP » gmane.comp.php.general » Replacing a special character

Vorheriges Thema: Does PHP support multi-thread ?
Nächstes Thema: compile php 5.3.2 with php-fpm error,HELP ME