Why is there: Warning: printf(): Too few arguments on line 59

我们两清 提交于 2019-12-25 04:26:03

问题


I get an error in my php code when trying to get all the files from their directory, then creating html links for them and I don't understand why.

Here is the error: Warning: printf(): Too few arguments in C:\Users\Ryan\Documents\Web Development\xampp\htdocs\muzik\player.php on line 59

Line 59 is: printf("<li><a href='mp3/%s'>%s</a></li>", htmlentities($file->getBasename()));

Here is the code:

`echo '<ul id="playlist">';
foreach( new DirectoryIterator('mp3/') as $file) {
    if( $file->isFile() === TRUE) {
        printf("<li><a href='mp3/%s'>%s</a></li>", htmlentities($file->getBasename()));
    }
}
echo '</ul>';`

回答1:


You have two %s, so the printf expects 2 arguments and you only put one.

You may want to use this one :

$filename = htmlentities($file->getBasename();
printf("<li><a href='mp3/%s'>%s</a></li>", $filename, $filename);


来源:https://stackoverflow.com/questions/22142897/why-is-there-warning-printf-too-few-arguments-on-line-59

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!