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 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用