How do I convert Word smart quotes and em dashes in a string?

前端 未结 13 1760
星月不相逢
星月不相逢 2020-11-29 03:11

I have a form with a textarea. Users enter a block of text which is stored in a database.

Occasionally a user will paste text from Word containing smart quotes or em

13条回答
  •  臣服心动
    2020-11-29 03:27

    This may not be the best solution, but I'd try testing to find out what PHP sees. Let's say it sees "–" (there are a few other possibilities, like simple "“" or maybe "“"). Then do a str_replace to get rid of all of those and replace them with normal quotes, before stuffing the answer in a database.

    The better solution would probably involve making the end-to-end data passing all UTF-8, as people are trying to help with in other answers.

提交回复
热议问题