Hi i have php which shows me all files in dir and make them href. But i have troubles with encoding. when i open file in web usin this php page, encoding is wrong. adding meta charset in head is not helping.
<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>
Use htmlentities
to encode everything properly:
$thelist .= '<a href="'.htmlentities($file) .'">'.htmlentities($file).'</a>';