我有一个带有 textarea 的表单.用户输入存储在数据库中的文本块.
有时,用户会粘贴 Word 中包含智能引号或短划线的文本.这些字符在数据库中显示为:–、–、–、–
我应该在输入字符串上调用什么函数来将智能引号转换为常规引号并将短划线转换为常规短划线?
我在 PHP 工作.
更新:感谢您到目前为止的所有精彩回复.Joel 网站上关于编码的页面非常有用:http://www.joelonsoftware.com/articles/Unicode.html
关于我的环境的一些说明:
MySQL 数据库使用 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:
htmlspecialchars() instead of
htmlentities().
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 智能引号和破折号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
MySQLi准备好的语句&foreach 循环MySQLi prepared statement amp; foreach loop(MySQLi准备好的语句amp;foreach 循环)
mysqli_insert_id() 是从整个服务器还是从同一用户获Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是从整个服务器还是从同一用户获取记录?)
PHP MySQLi 无法识别登录信息PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 无法识别登录信息)
mysqli_select_db() 需要 2 个参数mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 个参数)
Php mysql pdo 查询:用查询结果填充变量Php mysql pdo query: fill up variable with query result(Php mysql pdo 查询:用查询结果填充变量)
MySQLI 28000/1045 用户“root"@“localhost"的访问MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用户“root@“localhost的访问被拒绝)