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

前端 未结 13 1764
星月不相逢
星月不相逢 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:46

    The mysql database is using UTF-8 encoding. Likewise, the html pages that display the content are using UTF-8.

    The content of the HTML can be in UTF-8, yes, but are you explicitly setting the content type (encoding) of your HTML pages (generated via PHP?) to UTF-8 as well? Try returning a Content-Type header of "text/html;charset=utf-8" or add tags to your HTMLs:

    
    

    That way, the content type of the data submitted to PHP will also be the same.

    I had a similar issue and adding the tag worked for me.

提交回复
热议问题