当前位置:Gxlcms > PHP教程 > 哪位帮改下正则的问题?

哪位帮改下正则的问题?

时间:2021-07-01 10:21:17 帮助过:11人阅读

想模拟一下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

回复内容:

想模拟一下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

把 add_quote 改成这样试试?

function add_quote($v){
  $v = preg_quote(':', $v);
  return $v.'\b/';
}

这里有一个正则表达式教程,介绍了相关的问题:
http://deerchao.net/tutorials/regex/regex.htm#getstarted

人气教程排行