如何在字符串中转换Word智能引号和破折号? [英] How do I convert Word smart quotes and em dashes in a string?
问题描述
我有一个带有文本区域的表格.用户输入存储在数据库中的文本块.
有时,用户会从Word中粘贴包含智能引号或破折号的文本.这些字符在数据库中显示为:,",,".
我应该在输入字符串上调用什么函数,以将智能引号转换为常规引号,将引号转换为常规破折号?
我正在使用PHP.
更新:谢谢您到目前为止的所有好评. Joel网站上有关编码的页面内容非常丰富: http://www.joelonsoftware.com/articles /Unicode.html
关于我的环境的一些说明:
MySQL数据库使用UTF-8编码.同样,显示内容的HTML页面通过显式设置元内容类型来使用UTF-8(更新:).
在这些页面上,智能引号和破折号显示为带有问号的菱形.
解决方案:
再次感谢您的答复.解决方案是双重的:
- 确保数据库和HTML 文件已明确设置为使用 UTF-8编码.
- 使用
htmlspecialchars()
代替htmlentities()
.
这听起来像是Unicode问题. Joel Spolsky在该主题上有一个很好的起点: http://www.joelonsoftware.com/articles /Unicode.html
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 emdashes. Those characters appear in the database as: â€", ’, “ ,â€
What function should I call on the input string to convert smart quotes to regular quotes and emdashes to regular dashes?
I am working in PHP.
Update: Thanks for all of the great responses so far. The page on Joel's site about encodings is very informative: http://www.joelonsoftware.com/articles/Unicode.html
Some notes on my environment:
The MySQL database is using UTF-8 encoding. Likewise, the HTML pages that display the content are using UTF-8 (Update:) by explicitly setting the meta content-type.
On those pages the smart quotes and emdashes appear as a diamond with question mark.
Solution:
Thanks again for the responses. The solution was twofold:
- Make sure the database and HTML files were explicitly set to use UTF-8 encoding.
- Use
htmlspecialchars()
instead ofhtmlentities()
.
This sounds like a Unicode issue. Joel Spolsky has a good jumping off point on the topic: http://www.joelonsoftware.com/articles/Unicode.html
这篇关于如何在字符串中转换Word智能引号和破折号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!