1

I have a strange error

When i run the following code, once in a while i get

Warning: printf(): Too few arguments in /www/api/class.InvoicePayment.inc.php on line 92

However i don't understand why this happens because in my coding i have this line as

if($output!="")
      printf($output);

how can the this printf get a warning even when the output variable is not empty ..

2
  • 1
    us3.php.net/manual/en/function.printf.php Basically your output has some kind of placeholder, e.g. %s, and you are not passing any values that should replace the placeholders. Commented Jul 17, 2012 at 1:34
  • 1
    One fix (assuming PHP's printf is similar to C's) is to change printf($output) to printf("%s", $output) Commented Jul 17, 2012 at 2:07

3 Answers 3

3

This could happen if $output contains one or more format specifiers. Can you use echo instead of printf?

Sign up to request clarification or add additional context in comments.

Comments

3

As written in the first answer by James McLeod, maybe that helps you:

printf(str_tr($output, '%', '%%');

You need to escape % characters of $output first. That's done by adding another % in front of them. See as well the sprintf manual page­Docs that explains the formatting codes, specifically this part:

6. A type specifier that says what type the argument data should be treated as. Possible types:

  • % - a literal percent character. No argument is required.

The important message here is that with %% instead of % no argument is required.

But that's merely for explanation, better is in you case:

print $output;

You do not need to do any formatted printing here, so use print­Docs instead of printf.

Comments

0
 $replyTemplate = '<div class="module_content">
                    <fieldset style="width:100%%; float:left;">
                        <table width="100%%" align="center" border="1">
                            <tr>
                                <td width="15%%">
                                    <h3>%s</h3>
                                </td>
                                <td width="85%%">
                                    <h3>2015/06/11 09:06</h3>
                                    <h4>%s</h4>
                                </td>
                            </tr>
                        </table>
                    </fieldset><div class="clear"></div>
                </div>';

and use sprintf instead printf.

Example from : https://stackoverflow.com/questions/30776376/using-printf-to-format-html-too-few-arguments

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.