删除MYSQL中的一堆转义引号
我有一个奇怪的问题 - 我正在将一些数据从一个 CMS 移植到另一个 CMS。两者都运行在 LAMP 上。
在旧的 CMS 中,数据是用斜杠存储在数据库中的。
示例:
Hi. Thanks for looking. It\'s \"awesome\".
旧 CMS 输出时正确显示为:
Hi. Thanks for looking. It's "awesome".
但在新 CMS 中,它们相同的文本简单存储如下,并且在输出时处理引号:
Hi. Thanks for looking. It's "awesome".
我已尝试直接在 mysql 上替换(),但是这只是转义了引号,并且删除了所有引号。然后我尝试用 php 取出所有数据,然后将其放回原处,不做任何事情,希望斜杠能够转义数据,我会很好,但运气不佳 - 这似乎适用于两个行,但查询被破坏。
有什么想法吗?我已经有一段时间没有玩过 add/stripslashes 等了。
谢谢
I have an odd one - I am porting some data from one CMS to another. Both run on LAMP.
In the old CMS, the data was stored, with slashes in the DB.
Examples:
Hi. Thanks for looking. It\'s \"awesome\".
That correctly displays when output by the old CMS as:
Hi. Thanks for looking. It's "awesome".
But in the new CMS, they same text is stored simply as the following and they deal with the quotes when it comes out:
Hi. Thanks for looking. It's "awesome".
I have tried replace() directly on mysql, but that just escapes the quote and it just removes all the quotes. Then I tried looking into pulling all the data out with php, and putting it back in, without doing anything hoping that the slashes would escape the data and I'd be good, but not such luck - that seems to work for one of two rows but the query gets broken.
Any ideas? It's been a while since I have played around with add/stripslashes, etc.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 PHP 中你必须做到这一点
in PHP you have to make it
如果您使用 PHP 导入数据,您将需要
执行
str_replace("'", "''")
对每个条目
。这就是 MYSQL 转义字符串的方式
if you use PHP to import your data you will want to perform -
str_replace("'", "''")
on each entry.
this is how MYSQL escapes strings