哪位帮改下正则的问题?
想模拟一下Pdo的bindParam功能
写了一段简答的代码,如下: 查看链接吧,我搞不定大段的代码: 代码图片展示 以上代码基本上可以实现简单的绑定功能,会输出拉下结果:
SELECT * FROM TABLE WHERE conId=1 AND title LIKE '测试' AND created<='12312321312' ORDER BY conId DESC LIMIT 1
但是情况特殊的话就不行了,比如:
$sql = "SELECT * FROM TABLE WHERE conId=:id AND test=:idte AND title LIKE :kw AND created<=:time ORDER BY conId DESC LIMIT 1";
$args = array('id'=>1,'idte'=>'tester','kw'=>'测试','time'=>12312321312); 把$sql和$args都修改一下,输出的结果就会混乱,看" test=1te"这里
SELECT * FROM TABLE WHERE conId=1 AND test=1te AND title LIKE '测试' AND created<='12312321312' ORDER BY conId DESC LIMIT 1
三槌D空幻狐
10 years, 10 months ago
Answers
把 add_quote 改成这样试试?
function add_quote($v){
$v = preg_quote(':', $v);
return $v.'\b/';
}
这里有一个正则表达式教程,介绍了相关的问题:
http://deerchao.net/tutorials/regex/regex.htm#getstarted
彻斯鲁·梅耶
answered 10 years, 10 months ago