dougourang1856 2011-10-14 17:09
浏览 27
已采纳

PHP中包含文件中的重音字符

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. 
  • 写回答

2条回答 默认 最新

  • douliang6563 2011-10-14 17:14
    关注

    One of the files contains the strings in ISO-8859-1, and the other as UTF-8 string.
    Now that your page is declared with the Latin-1 charset, the latter will come out with garbage characters.

    Don't mix the two. Either identify the UTF-8 script and convert it back to Latin-1. Or move to UTF-8 for everything.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误