In my index.php I replaced
<div class="site_content"> ... </div>
with
<?php include ("site_content.php"); ?>
whilst all contents of the upper were copy&pasted into site_content.php.
The content now shows strange characters and the german encoding and charset (UTF-8) are not recognized any more. Before the change the encoding worked fine. The header of the index.php looks like this:
<!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="de">
<head>
<title>...some title.... </title>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<meta name="description" content=" ...some desc ...."/>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<?php include ("parts_index/site_content.php"); ?>
</body>
</html>
How can I solve this?
I've solved it.
The answer is very simple. The included php file was ANSI while my index.php was of course utf-8. When I converted the included file (site_content.php) to utf-8 no BOM it solved my problem! Thank you anyway for your time!
OZ
Related
I'm using PHP to display people's information from a text file in an HTML table. Some of the text contains special characters (Köhler, François, František) and those characters are displayed as "�". I know this is because the encoding isn't set to charset="UTF-8", but I've set it using PHP's header() function as well as in the meta data in the <head>. In addition, I used Notepad to specifically save the file encoding as UTF-8.
When I inspect the page with
CTRL+Shift+i > Network > Headers
it includes "Content-Type:text/html; charset=UTF-8" under "Response Headers", so I think the browser should be getting the idea that the encoding is UTF-8.
What am I missing here?
Here's the code where I declare the charset in the PHP file
<?php
header('Content-Type:text/html; charset=UTF-8');
$ary_of_lines = file("customers.txt");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
....... more stuff .......
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" />
This is my first PHP-based web project. I have the web part of it working perfectly, but I'm having trouble with the mobile version. (Web hosting on godaddy linux)
What is the reason for my .php page not displaying? If I change it to .html, it works fine.
(I suspect the doctype, but not sure.)
Not sure if this code is necessary, but I'll leave out the body for the sake of space:
<?php include_once 'web/config.php'?>
<!DOCTYPE HTML>
<html>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN"
"http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>About - Mobile</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="keywords" content="About - Mobile" />
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
</head>
config.php:
$link = mysqli_connect($server, $db_user, $db_pass);
mysqli_select_db($link, $database);
// -=-=-=-=-=-=-=[ Getting Variables ]=-=-=-=-=-=-=- //
$query = "SELECT * FROM `misc`";
$result = $link->query($query);
while($info = mysqli_fetch_array($result)){
// -=-=-=-=-=-=-=[ Variables ]=-=-=-=-=-=-=- //
$pickupTime = $info['pickupTime'];
$deliveryTime = $info['deliveryTime'];
$minDeliveryPrice = $info['minDeliveryPrice'];
$Gtitle = $info['Gtitle'];
$emailAccount = $info['emailAccount'];
$phone = $info['phone'];
$mailSubject= $info['mailSubject'];
$address = $info['address'];
$city = $info['city'];
$zipcode = $info['zipcode'];
$companyTel = $info['companyTel'];
$companyEmail = $info["companyEmail"];
$facebookLink = $info['facebookLink'];
$twitterLink = $info['twitterLink'];
$googleLink = $info['googleLink'];
$termsOfService = $info['termsOfService'];
}
?>
Thanks in advance!
PHP is executed at server side, as long as the PHP script renders valid HTML (this however doesn't seem the case), the phones won't care.
In case PHP code is received by a browser, something is wrong with the sever (for instance you didn't install PHP at server side, or the webserver doesn't know when to call PHP to generate a webpage)
A browser never receives the PHP code (otherwise it would be easy for instance to hijack databases since the PHP code has somehow the password).
PHP executes on the server, the client doesn't know it is talking to PHP. You need not change PHP code when targeting mobile platforms.
Your issue appears to be corrupt HTML
<?php include_once 'web/config.php'?>
We should probably see the config.php file to see what is happening in there.
<!DOCTYPE HTML>
<html>
Here you open an <HTML> tag.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN"
"http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
Here you open another <HTML> tag, this is an issue. You should only have one <HTML> tag as your outer node in the document.
<head>
<title>About - Mobile</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="keywords" content="About - Mobile" />
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
</head>
You do not close your <HTML> tags and you do not have a body to render.
Well since you said you posted only the head. Im just gonna fix your html to at least make it valid. And regarding the php, other answers explain why php doesn't matter when viewing websites in browsers
<?php include_once 'web/config.php'?>
<!DOCTYPE HTML>
<html>
<head>
<title>About - Mobile</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="keywords" content="About - Mobile" />
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
</head>
<body>
....
</body>
</html>
If this doesn't work, then I am guessing that this line of php <?php include_once 'web/config.php'?> is outputting something which is messing up the html or in other words, make it invalid, so try removing it and then tryAlso what do you mean its not displaying? Like nothing shows up? Or does it give an (http and or php) error?
Currently I created simple website using include system
header.php - contains first part of HTML page (Head, meta tags, JS codes ... etc )
page.php - contains simple php code
page content
My main problem with arabic language
I have to put
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
in page.php, footer.php between <head> tags otherwise the arabic will not support correctly.
This prevents page validation because of these tags.
Is there any method to avoid this problem ?
Thanks
// Send a raw HTTP header
header ('Content-Type: text/html; charset=UTF-8');
// Declare encoding META tag, it causes browser to load the UTF-8 charset
// before displaying the page.
echo '<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />';
// Right to Left issue
echo '<body dir="rtl">';
Encode the arabic string into UTF-8 using a tool like this. (No need to change any settings - that link has the the correct settings you need).
Then use utf8_decode() to decode the string back.
Example:
<?php echo utf8_decode('your_encoded_string_goes_here'); ?>
Apart from all of the answers... Make sure your (HTML/PHP) files are saved with the right encoding utf-8
All you need is to put this
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
in a file that you include/include_once in your pages
EDIT. example:
header.html
<!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" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>my title in العربية</title>
</head>
<body>
mypage.php
<?php
include_once 'header.html';
?>
<p>
العربية
</p>
<?php
include 'foot.html';
?>
foot.html
<div>my footer</div>
</body>
</html>
1- Put this
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
2- You should also save the documents in UTF-8 not ANSI
Your headers should appear as the following:
<!DOCTYPE html>
<html lang="ar">
<head>
<meta charset="utf-8">
</head>
<body>
Save your document as utf-8
I am Copying Hindi Words From Google Translator and Pasting it in my php page. In editor It is Correctly displaying But at Browser it is showing "???/" Marks. I have included charset"utf-8" in header also.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta http-equiv="Content-Language" content="hi">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<span>मैं एक अच्छा प्रोग्रामर हूँ</span>
</body>
</html>
Copy this and Save this in one html file..and try to run..it'll work..