How do I convert Word smart quotes and em dashes in a string?(如何在字符串中转换 Word 智能引号和破折号?)
问题描述
我有一个带有 textarea 的表单.用户输入存储在数据库中的文本块.
有时,用户会粘贴 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 智能引号和破折号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在字符串中转换 Word 智能引号和破折号?


基础教程推荐
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何替换eregi() 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01