一个简单的正则表达式来替换sql条件运算符?

时间:2013-01-29 08:39:51

标签: php regex

我正在编写一个类来处理一些MySql函数 现在,我想要一个正则表达式模式来检测操作 请看我的代码:

$a = "user_id <> 2";


$generalOperators = "/[<>|[<][\sA-Za-z0-9]|>|<|=]([\sA-Za-z0-9])/";
$op = "$1";
$asd = preg_replace($generalOperators, $op, $a);
echo $asd;

这将回显user_id 2作为输出!
我是正则表达的新手 提前谢谢!

2 个答案:

答案 0 :(得分:1)

您还可以使用str_replace()添加更多要替换的项目

$in_str = str_replace(array('<', '>', '&', '{', '}', '*', '/', '(', '[', ']' , '@', '!', ')', '&', '*', '#', '$', '%', '^', '|','?', '+', '=','"',','), array(''), $str);

答案 1 :(得分:0)

$a    = "user_id <> 2";
$res  = preg_replace("/[<>]/","",$a);

echo $res;