Page 1 of 1

escaping format directive sprintf()

Posted: Tue Oct 14, 2003 1:38 pm
by kendall
Hello,

i have the following variable which is a query code fo mysql

Code: Select all

$query = "SELECT *, DATE_FORMAT(Date, '\\%d \\%m \\%Y') AS theDATE FROM online_events WHERE MATCH(Title,Description) AGAINST('%s') OR MONTH(Date) = '%s' OR YEAR(Date) = '%s' OR DAY('%s') ORDER BY Date ASC";
I'm using sprintf() to format the string

Code: Select all

$query = printf($query,$term,$month,$year,$day);
However i get an Error
Warning: printf(): Too few arguments in
i'm thinking its the
DATE_FORMAT(Date, '\\%d \\%m \\%Y') AS theDATE
so i'm trying to escape it but still get the error....how does sprintf() react if some of the arguments are NULL? does it strill try to format

can i false a variable inorder to sprintf()? i.e. sprint($var,$var1,$var = false);?

Kendall

Posted: Tue Oct 14, 2003 1:58 pm
by volka
use %% to get a % from sprintf
try

Code: Select all

<?php
echo sprintf('%%Y%s.%d.%s.%d.', false, false, NULL, NULL);
?>
to see for yourself how false and NULL are treated