I have a file that I am getting a very weird error on. The error is:
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 to be declared in the document or
in the transfer protocol.
the file this comes from is (indexmws.php):
session_start();
if(!isset($_SESSION['validUser']) || $_SESSION['validUser'] !== true){
header('Location: loginmws.php');
}
include_once('db.php');
include_once('amazonmws.php');
include_once('decidemws.php');
include_once('author.php');
include_once('amazonPricingMWS.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Decision Maker</title>
This is an exact duplicate of a file that does not throw the error (index.php)with the exception of adding amazonPricingMWS.php and redirecting to pages with mws.php in the title:
session_start();
if(!isset($_SESSION['validUser']) || $_SESSION['validUser'] !== true){
header('Location: login.php');
}
include_once('db.php');
include_once('amazon.php');
include_once('decide.php');
include_once('author.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Decision Maker</title>
can anyone explain to me why I am getting this error in indexmws.php?
The error is coming because the browsers expect the encoding format in the first 1024 bytes of the file. It may be the case that there is some content being outputted by the included files in the first case.
The browsers now buffer the first 1024 bytes of the file to check for the character encoding. If the encoding description is not encountered in the first 1024 bytes, this warning is displayed.
In your case, you can use a php header for specifying the content type before the other files are included:
header('Content-type: text/html; charset=utf-8');
For more information, read this:
http://gtmetrix.com/specify-a-character-set-early.html
I had similar problem But teh exact reason behind this was that I missed following to add
<meta content="utf-8" http-equiv="encoding">
in head tag after
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
Related
I am using CKEditor, i want to use Unicode and insert in database.
I copy the language and paste in CKEditor or input text and try to insert in database phpmyadmin. But I cannot get the desired output.
How to make my php website Unicode supportive. I am using HTML4 and i need to change my heading.
Here is my HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="ISO-8859-1">
I m using phpmyadmin, and i change collations and set it to utf8_general_ci.
And That solve my problem.
I have a problem with our E-Mail templates.
They worked fine until 2-3 days ago i have no idea what happened.
They should be utf8 encoded and get shown correctly in PHP Storm they look something like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body {
....
}
</style
</head>
<body>
<center>Content with unique characters like ěäüß</center>
</body>
</html>
But in the Email the output is completely rubbish:
Vaše zakázka etc.
I use the output buffer to get the template content and send it with PHPMailer.
There is no encoding anywhere but shouldn't be needed.
I tried utf8-encode/decode etc. It makes everything only worse.
The only thing that worked is to use tools like this http://www.percederberg.net/tools/text_converter.html
to convert the plain text into utf-8 and then the code looks like rubbish like in the mail output, but then you can manually correct every character.. that worked for some templates like in german with some äüß.... but in the Czech template you have to rewrite every single character.
Is there something that i missed? Something that i could try?
I used htmlentities() on the text parts of the templates and worked quite decent!
Example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body {
....
}
</style
</head>
<body>
<center><?php echo htmlentities("Content with unique characters like ěäüß"); ?></center>
</body>
Hope this helps someone!
My website runs in localhost without any errors; but when I added my site to CPpanel and run members.php page disapeared (it shows white background). Inspecting the page in console displays this error message :
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.
Inspecting the element shows only these lines:
<div style="clear:both;"></div>
</div>
</div>
</body>
</html>
From the error you get, please add this to your <head> ... </head>:
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-5">
If the charset above did not work, please try this instead:
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
And I hope you defined the before BODY part of your pages as this:
<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<title> Your Title</title>
</HEAD>
<BODY>
....
EDIT 2:
Before including other any other PHP files in your members.php, type this line first:
header('Content-type: text/html; charset=utf-8');
Have you something like this in header? You put instead of utf-8 encoding of your file.
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
I have a project which is in Persian language. On the admin side of this project some Persian text in anchor tag and button tag displays wrong although I use charset=utf-8.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "w3.org/TR/html4/loose.dtd">;
<html lang="fa" dir="rtl">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta content="noindex,nofollow" name="robots">
<title>osCommerce</title>
if your html is compatible with xhml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fa" dir="rtl">
<head>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
...
</head>
if you used Netbeans or eclipse or any IDE check if your project is using the utf-8 file encoding.
apart from this <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
you should also save the yourpage.php script file in utf-8 format.
I am having problem with byte order mark at the top of my php file. It is like - . For this there is an php warning is showing. I have removed the text twice. but it keeps coming. My file starts like this -
<?php include('PL/header.php'); ?>
Where 'header.php' is like this-
<?php require_once("BLL/index_isNotLoggedIn_bll.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
How can I solve this?
Your IDE is probably inserting the BOM whenever you save the file. You have to configure it to save as UTF-8 without the byte order mark.
How you do this depends on your IDE, check Google if needed.