【发布时间】:2010-05-24 09:00:32
【问题描述】:
看下面的字符串:
SELECT
column1 ,
column2, column3
FROM
table1
WHERE
column1 = 'text, "FROM" \'from\\\' x' AND
column2 = "sample text 'where' \"where\\\" " AND
( column3 = 5 )
我需要从字符串中转义不必要的空白字符,例如:
- 从 、( ) 等的开始和结束位置删除空格
- 删除换行符 (\r\n) 和制表符 (\t)
但有一件事。删除过程无法从引用的字符串中删除空格,例如:
- 'text, "FROM" \'from\\' x'
- "示例文本 'where' \"where\\" "
等等
我需要使用PHP函数:preg_replace($pattern, $replacement, $string);
那么 $pattern 和 $replacement 的值是多少,其中 $string 的值是给定的 SQL。
【问题讨论】:
标签: php string whitespace pattern-matching preg-replace