开发者

Encoding issues with PHP and apostrophes when pasted from MS Word

I have a form that emails to my email address. Everything works fine, except when someone pastes something from MS Word into the form. All the text comes through, but th开发者_JAVA百科e encoding on the apostrophes and double quotes are all messed up. They come through as strange characters.

Is there anyway to easily fix this issue?


For me this solution works fine:

Convert windows converted string to utf-8.

$str = iconv("cp1252","UTF-8", $str);
  • cp866 MS DOS Cyrillic
  • cp1251 Windows Cyrillic
  • cp1253 Windows west european language

Futher information about iconv()


MS Word uses apostrophes and quotes that are not valid under UTF8. Here's an article on SO about it:

PHP - Getting rid of curly apostrophes


Have you tried using strip_tags() ?


You need to have same charset on both the form html page, and the page which generates the email content. For example, set utf-8 on the html page which displays the form. Also, when creating the mail message on submit, set the charset in header to be utf-8. That works fine. If you are using phpmailer for email, then you can set the charset through the phpmailer class object like $mail->Charset = 'utf-8' This works well when you are storing and retrieving from database. The trick is to keep the encoding scheme same all through.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜