sprintf 参数太少
我之前已经这样做过很多次,以重新使用传递到 sprintf() 函数的值。但此代码返回“警告:sprintf() [function.sprintf]:参数太少...”消息。
代码如下:
$search_clause = sprintf(" (msgBody LIKE %%%1$s%% OR msgSubject LIKE '%%%1$s%%' ) ", mysql_real_escape_string($match1));
理想情况下, $match1 的值将被插入到上面所示的 SQL WHERE 子句的段中 - 两次,每次都用 '%' 字符包裹以进行通配符搜索。
如果 $match1 = "test",则 $search_clause 的结果字符串值将是:
(msgBody LIKE '%test' OR msgSubject LIKE '%test%' )
我犯的明显错误是什么?
I have done this many times before, to re-use a value passed into the sprintf() function. But this code is returning a "Warning: sprintf() [function.sprintf]: Too few arguments in..." message.
Here is the code:
$search_clause = sprintf(" (msgBody LIKE %%%1$s%% OR msgSubject LIKE '%%%1$s%%' ) ", mysql_real_escape_string($match1));
Ideally the value of $match1 will be inserted into the segment of the SQL WHERE clause shown above - twice, each wrapped by '%' characters for a wildcard search.
If $match1 = "test", the resulting string value of $search_clause would be:
(msgBody LIKE '%test' OR msgSubject LIKE '%test%' )
What is the obvious mistake I'm making??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
$s
可能被解释为变量(请参阅变量扩展)。尝试使用单引号代替:The
$s
is probably getting interpreted as a variable (see variable expansion). Try using single quotes instead:只需将
$
转义为\$
即可。Just escape the
$
as\$
.