Skip to content
PHP Logo

How can the issue of displaying "." and ".." in a PHP script be prevented?

The issue of displaying "." and ".." in a PHP script can be prevented by using the `scandir()` function to get the list of files and directories in a directory, and then filtering out "." and ".." from the results before displaying them.

php
$dir = "/path/to/directory";
$files = array_diff(scandir($dir), array('.', '..'));

foreach($files as $file){
    echo $file . "<br>";
}