I'm programming a quite simple PHP Script, that writes a string (sentence) got from an HTML FORM into a file. This string sometimes contains Non-ASCII Characters, in my case german umlauts, äöü. But instead of writing them to the file correctly it just writes little question-mark-symbols.
How can I fix that?
<?php
header('Content-type: text/html; charset=utf-8');
# $_POST["message"]
# $_POST["random"]
# $_POST["date"]
#$MESSAGE = utf_encode($_POST["message"]);
$countfile = fopen("filecount", "r");
$filecount = fread($countfile,filesize("filecount"));
fclose($countfile);
$filename = $filecount + 1;
echo($filename);
if ($_POST["random"]){
$newmessagefile = fopen($filename, "w");
fwrite($newmessagefile, $_POST["message"]);
fclose($newmessagefile);
$countfilew = fopen("filecount", "w");
fwrite($countfilew, $filename);
fclose($countfilew);
}
else {
$newmessagefile = fopen($_POST["date"], "w");
fwrite($newmessagefile, $_POST["message"]);
fclose($newmessagefile);
$specialdaysfile = fopen("specialdays", "a");
fwrite($_POST["date"]);
fclose($newmessagefile);
}
?>