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);
Question
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>';`
Solution
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);