Home > Backend Development > PHP Tutorial > 哪位帮改下正则的问题?

哪位帮改下正则的问题?

WBOY
Release: 2016-06-06 20:49:31
Original
947 people have browsed it

想模拟一下Pdo的bindParam功能

写了一段简答的代码,如下: 查看链接吧,我搞不定大段的代码:代码图片展示 以上代码基本上可以实现简单的绑定功能,会输出拉下结果:

<code>SELECT * FROM TABLE WHERE conId=1 AND title LIKE '测试' AND created</code>
Copy after login
Copy after login

但是情况特殊的话就不行了,比如:

<code>$sql = "SELECT * FROM TABLE WHERE conId=:id AND test=:idte AND title LIKE :kw AND created</code>
Copy after login
Copy after login

$args = array('id'=>1,'idte'=>'tester','kw'=>'测试','time'=>12312321312); 把$sql和$args都修改一下,输出的结果就会混乱,看" test=1te"这里

<code>SELECT * FROM TABLE WHERE conId=1 AND test=1te AND title LIKE '测试' AND created</code>
Copy after login
Copy after login

回复内容:

想模拟一下Pdo的bindParam功能

写了一段简答的代码,如下: 查看链接吧,我搞不定大段的代码:代码图片展示 以上代码基本上可以实现简单的绑定功能,会输出拉下结果:

<code>SELECT * FROM TABLE WHERE conId=1 AND title LIKE '测试' AND created</code>
Copy after login
Copy after login

但是情况特殊的话就不行了,比如:

<code>$sql = "SELECT * FROM TABLE WHERE conId=:id AND test=:idte AND title LIKE :kw AND created</code>
Copy after login
Copy after login

$args = array('id'=>1,'idte'=>'tester','kw'=>'测试','time'=>12312321312); 把$sql和$args都修改一下,输出的结果就会混乱,看" test=1te"这里

<code>SELECT * FROM TABLE WHERE conId=1 AND test=1te AND title LIKE '测试' AND created</code>
Copy after login
Copy after login

把 add_quote 改成这样试试?

<code>function add_quote($v){
  $v = preg_quote(':', $v);
  return $v.'\b/';
}
</code>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template