I have a string called $tabledetail that is built in a set of where and if statements. When I echo the string using the following statement

echo "$tabledetail\n";

I get the following output:

"<tr><td><font color='white'><a href='libraryonlinesearchsummary.php3?id=%s&title=%s' target='_blank'>%
s</a></td><td><font color='white'>%s</td><td><font color='white'>%s</td><td><font color='white'>%s</td><td><font color='white'>%s</td><td><font color='white'>%s</td><td><font color='white'>%s</td><td><font color='white'>%s</td></tr>", $sequenceidrow, $titlerow, $titlerow, $authorsrow, $pagesrow, $copyrightdaterow, $coverrow, $numberofcopiesrow, $callnumberrow, $authorsabbrrow

The above strings that are supposed to be substituted into each %s field are coming from a database. However, when I try to do the printf statement like this:

printf ($tabledetail);

I get the following error:

Warning: printf(): too few arguments in /home/countrys/countrysidechristian-www/interactivemultimedia/churchlibrary/libraryonlinesearch.php3 on line 214

Any help with what I am doing wrong with my printf statement is appreciated.

Thanks,
Brian

    You are getting two functions confused. echo doesn't use %s formatters. Only printf does (hence the f which means print format). If you use echo you need only place the variables in the actual string itself, ie:

    echo "$var is variable";

    where a printf would be:

    printf("This is my variable: %s\n",$var);

    You use one or the other, not one to call the other.

      what am I doing wrong

      The whole point of printf() is to insert subsequent arguments into places in the first argument where you have included a format-specifier. These all begin with %. In the variable you are passing as parameter 1, there is an embedded %s (and perhaps more, but it displayed here in white text and was kind of hard to read.) Thus, printf is expecting (at least) one more argument which is a string.

      If you really aren't using printf() to arguments into the first string, consider using print or echo instead. Or, if you insist on using printf, the canonical safe way to use it to print a single string of unknown origin is:

      printf("%s", $any_string_is_safe_here );

        Write a Reply...