php中文乱码
一个简单的数据库插入界面和后台
add.html
<script type="text/javascript" language="javascript">
function onAddItem()
{
var xmlhttp;
var workcontent = $("#tb_content").attr("value");
var contact = $("#tb_contact").attr("value");
var remark = $("#tb_remark").attr("value");
if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}else{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
var requestStr = "add.php?content="+workcontent + "&contact="+contact +"&remark="+remark;
xmlhttp.open("GET",requestStr,true);
xmlhttp.send();
alert(requestStr);
}
</script>
后台 add.php
<?php
$workcontent = $_REQUEST["workcontent"];
$contact = $_REQUEST["contact"];
$remark = $_REQUEST['remark'];
include 'conn.php';
$sql = "insert into WorkContentTable(workcontent,contact,remark) values('$workcontent','$contact','$remark')";
$issuccess = @mysql_query($sql);
if(!issuccess){
echo "添加不成功!";
}else{
$str = "添加了一条数据,业务内容为:" + $workcontent + ",联系人为:" + $contact + ",备注为:" + $remark;
echo $str;
}
?>
mysql的编码为默认的utf-8
在firefox浏览器中操作,mysql为中文正常显示
在IE中操作,mysl中文乱码
add.php?workcontent=测试&contact=test&remark=ss
firefox和ie均echo出乱码
本人php新手 这个中文乱码问题搞的真纠结
网上找的方法都试过了 没用 iconv函数转码之后为空串
------解决方案--------------------遇到过类似问题,不懂其中原因,当时我这样
$bm = array('UTF-8','GBK');
$charTest;
foreach($bm as $c){
if( $tag === iconv('UTF-8', $c, iconv($c, 'UTF-8', $tag))){//转换编码后是不是相等