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

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

    You could try mb_ convert_encoding from ISO-8859-1 to UTF-8.

    $str = mb_convert_encoding($str, 'UTF-8', 'ISO-8859-1');
    

    This assumes you want UTF-8, and convert can find reasonable replacements... if not, mb_str_replace or preg_replace them yourself.

提交回复
热议问题