Too few sprintf arguments

I have done this many times before to reuse the value passed to the sprintf () function. But this code returns the message "Warning: sprintf () [function.sprintf]: Too few arguments ...".

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 of which is wrapped with “%” characters to search for wildcards.

If $ match1 = "test", the resulting string value of $ search_clause will be:

(msgBody LIKE '%test' OR msgSubject LIKE '%test%' )

What obvious mistake am I making ??

+3
source share
2 answers

$s, , (. ). :

$search_clause = sprintf(' (msgBody LIKE "%%%1$s%%" OR msgSubject LIKE "%%%1$s%%" ) ', mysql_real_escape_string($match1));
+11

$ \$.

$search_clause = sprintf(" (msgBody LIKE %%%1\$s%% OR msgSubject LIKE '%%%1\$s%%' ) ", mysql_real_escape_string($match1));
                                             ^                             ^
+2

Source: https://habr.com/ru/post/1779439/


All Articles