【问题标题】:How to set UTF8 on PHP when connect to ACCESS 2007 (ODBC)连接到 ACCESS 2007 (ODBC) 时如何在 PHP 上设置 UTF8
【发布时间】:2012-10-21 10:14:02
【问题描述】:

Access 文件中有泰文、日文、韩文字符(3 个字段)。

我在 PHP 中创建了一个脚本来连接到这个文件

但显示的字符显示 ??????? ??????还有??????

设置什么来显示正常字符

这是我的脚本

<html>
<head>
<title>TEST</title>
</head>
<body>
<?
$objConnect = odbc_connect("test","","") or die("Error Connect to Database");
$strSQL = "SELECT * FROM table1";
$objExec = odbc_exec($objConnect, $strSQL) or die ("Error Execute [".$strSQL."]");
?>
<table width="600" border="1">
  <tr>
    <th width="20"> <div align="center">ID </div></th>
    <th width="30"> <div align="center">Thai </div></th>
    <th width="30"> <div align="center">Korea </div></th>
     <th width="30"> <div align="center">Japan </div></th>

  </tr>
<?
while($objResult = odbc_fetch_array($objExec))
{
?>
  <tr>
    <td><?=$objResult["ID"];?></div></td>
    <td><?=$objResult["Thai"];?></td>
    <td><?=$objResult["Korea"];?></td>
    <td><?=$objResult["Japan"];?></div></td>
  </tr>
<?
}
?>
</table>
<?
odbc_close($objConnect);
?>
</body>
</html>

【问题讨论】:

  • PHP 的哪个版本?旧版本不支持 utf-8

标签: php utf-8 character-encoding odbc ms-access-2007


【解决方案1】:
 <?
  header('Content-Type: text/html;charset=utf-8');
 ?>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>TEST</title>
</head>
<title>TEST</title>

<body>

<?
$objConnect = odbc_connect("test","","") or die("Error Connect to Database");
odbc_exec($objConnect, "SET NAMES 'UTF8'");
odbc_exec($objConnect, "SET client_encoding='UTF-8'");

...

或者排队试试:

<td><?=mb_convert_encoding($objResult["Japan"], "SJIS");?></td>

【讨论】:

  • 您可以在 firefox / firebug 的标题页中签入吗?如果你在数据库上做一个选择,字符显示OK?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多