$query = preg_replace( '|(?<!%)%s|', "'%s'", $query ); // quote the strings, avoiding escaped strings like %%s这是wordpress wp-db.php prepare 方法中的一句,其中正值 |(?<!%)%s| 不知怎么理解小弟是新手,还请哪位大侠能详细解释一下,不胜感谢!

解决方案 »

  1.   

    1.(?:):非捕获模式.
    2.(?=):右预测等于模式.
    3.(?!):右预测不等于模式.
    4.(?<=):左预测等于模式.
    5.(?<!):左预测不等于模式.
    模式:|(?<!%)%s|
    首先两竖线不用管了,模式起始标志,从Perl遗传过来的.
    对应(?<!%)为第5种情况,可知,在匹配到%s字符时需要进行回退判断,即%s前的字符不等于%
    quote the strings, avoiding escaped strings like %%s
    从E文翻译过来再去理解模式.