Warning: sprintf(): Too few arguments in functions.php

前端 未结 2 968
悲&欢浪女
悲&欢浪女 2020-12-22 05:32

I\'m getting this PHP error in my custom breadcrumb function:

Warning: sprintf(): Too few arguments in /srv/bindings/56058a57d7424f84adac37ba6b03d3b7

相关标签:
2条回答
  • 2020-12-22 06:10
    1. dont use % sign in your string when use sprintf method

    in my case: for example:

    $data = call_web_service(); // return array()
    foreach ($data as $d)
    echo sprintf("<div>our %65 discount is : %s </div>",
    $d["discount"]
    );
    

    use %65 in my string

    sprintf seek every % and if counts of them is not equal to your parameters return this error

    1. dont use < ?php or ? > in your string

    like this :

    $weekday = "sunday";
    echo sprintf("<div>our <?php echo $date;?> day is : %s </div>",
    $weekday
    );
    
    0 讨论(0)
  • 2020-12-22 06:22

    Your sprintf string has 2 placeholders, your filling one.

    <?php
    // bad
    echo sprintf('<a href="%1$s">%2$s</a>', 'http://example.com');
    
    // good
    echo sprintf('<a href="%1$s">%2$s</a>', 'http://example.com', 'Link Name');
    

    https://3v4l.org/nu8Ht

    0 讨论(0)
提交回复
热议问题