I have a webpage that outputs a string that contains accented characters.
I have the variable $myGlobalStr
that is declared in the main page, and then is returned via the function outputGlobalVariable()
. Everything work as expected.
When I declare that very same string within the function outputFunctionVariable()
, the output is in UTF-8 format..
I tried to use <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
in my page, ad I also tried to include header('Content-type: text/html; iso-8859-1')
at the beginning of my include file. Both doesn't work.
I never had to specify a charset in an include file before. I know I can use the function utf8_decode()
in outputFunctionVariable() but I'm interested to understand why it's happening and the logical behind this...
I'm using Zend Server CE on Windows.
index.php
<?
$myGlobalStr = "1. Dites bonjour à l'élève.";
include("includes/functions.php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test</title>
</head>
<body>
<?=outputGlobalVariable()?>
<hr>
<?=outputLocalVariable()?>
</body>
</html>
functions.php
<?
function outputGlobalVariable() {
global $myGlobalStr;
return $myGlobalStr;
}
function outputLocalVariable() {
$myStr = "2. Dites bonjour à l'élève.";
return $myStr;
}
?>
output
1. Dites bonjour à l'élève.
------------
2. Dites bonjour à l'élève.