I have a PHP file which, when run produces a white screen and this error: "The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol." Looking at other answers on this site the most common answer is to add
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
in the <head>
. However I have this and am still getting the error. I have also tried
header('Content-type: text/html; charset=utf-8');
in the PHP and it still doesnt work. When I remove all my php code it works, anyone know what I might have in my code to cause this error? Im a bit of a novice to PHP and still dont really know what im doing. my full php code is so:
$favisit = $favanimal = $age = $area = "";
$viserror = $anierror = $ageerror = $areaerror = "";
$errormessage = $extra = "";
$errorlist = [$viserror,$anierror,$ageerror,$areaerror]
$counter = 0;
if ($_SERVER["REQUEST_METHOD"]=="POST") {
if (empty($_POST["favisit"])) {
$viserror = " the favorite bit of your visit";
} else {
$favisit = test_input($_POST["favisit"]);
}
if (empty($_POST["favanimal"])) {
$anierror = " your favorite animal";
} else {
$favanimal = test_input($_POST["favanimal"]);
}
if (empty($_POST["age"])) {
$ageerror = " your age";
} else {
$age = test_input($_POST["age"]);
}
if (empty($_POST["area"])) {
$areaerror = " the area where you live";
} else {
$area = test_input($_POST["area"]);
}
}
foreach($errormessage as $error) {
if ($error == "") {
$counter = $counter+1
}
}
if ($counter != 0) {
$errormessage = "You have not filled out"
if ($counter == 1) {
foreach($errormessage as $error) {
if ($error == "") {
$errormessage = $errormessage . $error . ".";
}
}
} else {
$extra = ","
foreach($errormessage as $error) {
if ($error == "") {
if ($counter == 1) {
$extra = " or"
}
$errormessage = $errormessage + $extra + $error + ".";
$counter = $counter -1;
}
}
}
}
Again I'm still a novice to PHP so its probably a stupid mistake I cant pick up on. Thanks in advance!