长话短说,由于 PHP 魔术引号,我的数据中有反斜杠。我已经解决了那里的问题,但现在有一些记录有不必要的反斜杠。
1 | This is an example of \' single, \" double, and \\ backslash (in the messed up records)
2 | This example is how it gets stored now \ backslash ' single " double
Run Code Online (Sandbox Code Playgroud)
当我想输出我的数据时,我需要使用斜杠来解决问题并获得以下输出:
1 | This is an example of ' single, " double, and \ backslash
Run Code Online (Sandbox Code Playgroud)
但是这个是错误的:
2 | This example is how it gets stored now backslash ' single " double
Run Code Online (Sandbox Code Playgroud)
因此,我的 php 中的 stripslashes 删除了一个在技术上不用于转义任何内容的斜线。
我不想使用斜杠,因为我的数据应该像这样干净:
1 | This is an example of ' single, " double, and \ backslash (how data should be)
Run Code Online (Sandbox Code Playgroud)
我怎样才能查询到替代\'
和\"
并\\
用'
"
和\
?
DROP TABLE IF EXISTS tmpTable;
CREATE TEMPORARY TABLE IF NOT EXISTS tmpTable ( BadText VARCHAR(100));
INSERT INTO tmpTable
SELECT 'This is an example of \\\' single, \\\"double, and \\\\ backslash';
select BadText from tmpTable;
update tmpTable
set BadText = replace(replace(replace(BadText,'\\\'','\''),'\\\"','"'),'\\\\','\\');
select BadText as GoodText from tmpTable;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
27505 次 |
最近记录: |