문제

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>';`
도움이 되었습니까?

해결책

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top