Php 目录中文件的编码列表

Php 目录中文件的编码列表,php,html,Php,Html,嗨,我有php,它显示了dir中的所有文件,并使它们成为href。但是我在编码方面有困难。当我用这个php页面在web中打开文件时,编码是错误的。在head中添加元字符集没有帮助 <html> <head> <meta http-equiv="Content-Type" content="application/html; charset=utf-8" /> </head> <body> <

嗨,我有php,它显示了dir中的所有文件,并使它们成为href。但是我在编码方面有困难。当我用这个php页面在web中打开文件时,编码是错误的。在head中添加元字符集没有帮助

<html>
    <head>
    <meta http-equiv="Content-Type" content="application/html; charset=utf-8" />
    </head>
    <body>
    <?php
     if ($handle = opendir('/opt/nagios/share/kpi_backup')) {
       while (false !== ($file = readdir($handle)))
          {
              if ($file != "." && $file != "..")
              {
                    $thelist .= '<a href="'.$file.'">'.$file.'</a>';
              }
           }
      closedir($handle);
      }

    ?>
    <p>List of files:</p>
    <p><?=$thelist?></p>
    </body>
    </html>

文件列表:

用于正确编码所有内容:

$thelist .= '<a href="'.htmlentities($file) .'">'.htmlentities($file).'</a>';
$thelist.='';

使用
htmlentities()
对所有内容进行正确编码。您能举个例子吗?谢谢,但它对我不起作用,尝试了htmlenties($file,“windows-1251”)