PHP string infected with weird characters.

Status
Not open for further replies.

littleBird

New Member
Since building a simple blog tool a few weeks ago I have been wrestling with some mysterious characters that infect in the users input. The user in questions is using a Windows system that for some reason enters characters like " or - in a none standard way. The result, blog entries with stuff like �

Anybody have an idea why this is happening and more crucially how I can eradicate it!
 

kae

New Member
they're probably pasting from Word. Instead of producing a double-quote like ", Word has two different types for the left side and right side of a string. The "strange" hyphen (-) is probably an "em dash".

If you use the UTF-8 character set, you should see this stuff solved.
 

louie

New Member
It seems somebody is trying to break your website or is purelly mistake.

first you should try to convert the user input into html char() and then before insterting the data add some php functions to protect the database.

PHP:
$your_field = htmlspecialchars($your_field);//convert html char
 
$your_field = (!get_magic_quotes_gpc()) ? addslashes($your_field) : $your_field; //add magic quotes and/or slashes

you could also use
PHP:
 str_replace
function
 

littleBird

New Member
Apologise for not responding before, thank you for your advice. I have tried the various approaches suggested but have failed to resolve the issue satisfactorily.

Due to other more pressing matters and the fact that the circumstances around the data entry can be completely controlled I have opted for a human solution. Put manners on the person who was pasting their entries from MS Word.

I am sure with the aid of your suggestions I could resolve this technically but this year I am trying to learn how to avoid time holes. Those unexpected issues that become technical challenges that eat up all your time, yet must be resolved just so you can prove to yourself that you can...
 

georgiecasey

New Member
I am sure with the aid of your suggestions I could resolve this technically but this year I am trying to learn how to avoid time holes. Those unexpected issues that become technical challenges that eat up all your time, yet must be resolved just so you can prove to yourself that you can...

Lol, know exactly what you're talking about.
 

louie

New Member
if you are using it for textarea field, add FKeditor to it with minimum buttons and edit the javascript and where it says "force paste to plain text" change from false to true. That should help a lot.
 
Status
Not open for further replies.
Top