学过的很简单,一段代码,现在出现中文乱码,如下<!--<?php
print <<<EOT
-->
</td><td class="middleright"></td></tr><tr><td class="bottomleft"></td><td class="bottomcenter"></td><td class="bottomright"></td></tr>
</table><!--body container END-->
<div class="footer">
Total {$timer_run}(s) query {$times}, Time now is:{$time_now}  {$cache_settings['icp']}<br />
中文出乱码<a href="http://baidu.com" target="_blank">中文出乱码</a> 中文乱码
</div>
{$cache_settings['counter']}
<script>
var oldid;
function selectMenu(id){
if(oldid){
document.getElementById("sec_"+oldid).style.display ="none";
document.getElementById(oldid).className='header_121_a';
}
oldid=id;
document.getElementById(id).className='header_121_cur';
document.getElementById("sec_"+id).style.display ="";
}
try{
if(window.location.href.indexOf('member.php')>-1){
selectMenu('hmenu_member');
}else{
selectMenu('hmenu_bbs');
}
}catch(err){

}function getSearchLink(){
var v=document.getElementById("search_input").value;
window.location.href="search.php?action=search&k="+encodeURIComponent(v)+"&fid=0&area=1&topictypestr=all&topicspc=all&starttime=&stoptime=";
}</script>
<script type="text/javascript">
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3Ff22726cf01a3f514327e5eac33e9a0e4' type='text/javascript'%3E%3C/script%3E"));
</script>
</body>
</html>
<!--
EOT;
?>
-->我试了两种方法都没成功,听说PHP页面的编码要用函数,但我我不知道,求解,把改好的发出来,结贴及时。

解决方案 »

  1.   

    乱码的话 就用一下这个函数 iconv('gb2312','utf-8',$str);    $str 要转换的字符串这个的函数就是 将 $str 从gb2312 转换为 utf-8 编码的字符串....试一下.   转码后的字符串 后面再拼接 字符串的话  可能会出现乱码情况, 建议转码后加上 几个点, 如下:
    //拼接上几个点   后面打印到模板就不用怕 与标签发生拼接乱码啦
    $str = iconv('这个编码','转到这个编码',$str)."...";    字符串截取、字符串转码 都可能会遇到 拼接处 乱码现象.
      

  2.   

    1、编码转换
    $value=iconv("utf-8","gb2312",$value);2、检查php.ini配置
      

  3.   

    <!--<?php
    print <<<EOT
    -->
    </td><td class="middleright"></td></tr><tr><td class="bottomleft"></td><td class="bottomcenter"></td><td class="bottomright"></td></tr>
    </table><!--body container END-->
    <div class="footer">
    Total {$timer_run}(s) query {$times}, Time now is:{$time_now} {$cache_settings['icp']}<br />
    中文出乱码...<a href="http://baidu.com" target="_blank">中文出乱码...</a> 中文乱码...
    </div>
    {$cache_settings['counter']}
    <script>
    var oldid;
    function selectMenu(id){
    if(oldid){
    document.getElementById("sec_"+oldid).style.display ="none";
    document.getElementById(oldid).className='header_121_a';
    }
    oldid=id;
    document.getElementById(id).className='header_121_cur';
    document.getElementById("sec_"+id).style.display ="";
    }
    try{
    if(window.location.href.indexOf('member.php')>-1){
    selectMenu('hmenu_member');
    }else{
    selectMenu('hmenu_bbs');
    }
    }catch(err){}function getSearchLink(){
    var v=document.getElementById("search_input").value;
    window.location.href="search.php?action=search&k="+encodeURIComponent(v)+"&fid=0&area=1&topictypestr=all&topicspc=all&starttime=&stoptime=";
    }</script>
    <script type="text/javascript">
    var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
    document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3Ff22726cf01a3f514327e5eac33e9a0e4' type='text/javascript'%3E%3C/script%3E"));
    </script>
    </body>
    </html>
    <!--
    EOT;
    ?>
    -->楼主拿去 试一下,  以前我遇到乱码问题.... 你用了 字符串截取吧.
      

  4.   

    在的html中加上<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">保证数据库,文件编码,页面编码保持统一.不一致需要用函数进行转码.
    mb_convert_encoding();
      

  5.   

    在数据库建表时加上一句
    DEFULT charset=gbk
      

  6.   

    你首先要确认你页面的编码,看看你头部本身是什么编码
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    然后看看你数据库对应的库是什么编码,要保证一致,不然就需要转码,最好都统一为UTF8编码,就没这个问题了。
      

  7.   


    在这个<!--<?php的下面加一句:
    header("Content-type:text/html;charset=gbk");