php页面中文乱码的问题!基础,不过我就是不知道

醉卧美人 2011-03-14 04:14:38
学过的很简单,一段代码,现在出现中文乱码,如下

<!--<?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页面的编码要用函数,但我我不知道,求解,把改好的发出来,结贴及时。
...全文
290 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
Abin-2008 2011-03-15
  • 打赏
  • 举报
回复
junchen168168 2011-03-15
  • 打赏
  • 举报
回复
好多的编码问题!呵呵!
life169 2011-03-15
  • 打赏
  • 举报
回复

在这个<!--<?php的下面加一句:
header("Content-type:text/html;charset=gbk");
babyboyren 2011-03-15
  • 打赏
  • 举报
回复
你首先要确认你页面的编码,看看你头部本身是什么编码
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
然后看看你数据库对应的库是什么编码,要保证一致,不然就需要转码,最好都统一为UTF8编码,就没这个问题了。
auvmonkey 2011-03-15
  • 打赏
  • 举报
回复
在数据库建表时加上一句
DEFULT charset=gbk
醉卧美人 2011-03-14
  • 打赏
  • 举报
回复
还是毛用
醉卧美人 2011-03-14
  • 打赏
  • 举报
回复
4楼骗我 改都没改
daly2008 2011-03-14
  • 打赏
  • 举报
回复
在的html中加上

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

保证数据库,文件编码,页面编码保持统一.不一致需要用函数进行转码.
mb_convert_encoding();
guatoujiangyou 2011-03-14
  • 打赏
  • 举报
回复
<!--<?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;
?>
-->



楼主拿去 试一下, 以前我遇到乱码问题.... 你用了 字符串截取吧.


醉卧美人 2011-03-14
  • 打赏
  • 举报
回复
头晕 能不能把改好的发下
zsl_007 2011-03-14
  • 打赏
  • 举报
回复
1、编码转换
$value=iconv("utf-8","gb2312",$value);

2、检查php.ini配置
guatoujiangyou 2011-03-14
  • 打赏
  • 举报
回复
乱码的话 就用一下这个函数 iconv('gb2312','utf-8',$str); $str 要转换的字符串



这个的函数就是 将 $str 从gb2312 转换为 utf-8 编码的字符串....试一下. 转码后的字符串 后面再拼接 字符串的话 可能会出现乱码情况, 建议转码后加上 几个点, 如下:


//拼接上几个点 后面打印到模板就不用怕 与标签发生拼接乱码啦
$str = iconv('这个编码','转到这个编码',$str)."...";

字符串截取、字符串转码 都可能会遇到 拼接处 乱码现象.

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧