我通过ODBC连接到Filemaker DB,并且一些数据包含重音,例如:
$connection = odbc_connect($dsn, $username, $password, SQL_CUR_USE_ODBC);
$sql = "SELECT * FROM Table1";
$res = odbc_exec($connection,$sql);
while ($row = odbc_fetch_array($res)){
$x++;
$values= ($x . ": Customer:". $row['Customer'] . "'n");
print($values);
}
odbc_free_result($res);
odbc_close($connection);
我尝试了一些事情,比如在标题中添加'charset=utf-8',但到目前为止似乎没有任何效果。我很确定我需要在某个地方包含utf-8,我只是没有在网上找到与我的代码类似的odbc示例。谢谢!
您需要使用正确的编码进行连接。您可以使用以下查询来确定正确的编码:
SELECT hex(CustomerCustomer) FROM Table1;
将违规字符的十六进制代码与目标编码相匹配,最可能的是latin1
和UTF-8
。如果您不能识别十六进制代码,那么将输出粘贴到这里,我将为您识别。
ODBC使用名为WIN1252的编码类型。
试一试:
mb_convert_encoding($value,'UTF-8','Windows-1252');
我用它来做相反的win1252到utf8通过这种方式应该工作…让我知道
所以试试吧:使用函数mb_detect_encoding()。如果这个函数不存在,试试下面的代码。
if ( !function_exists('mb_detect_encoding') ) {
function mb_detect_encoding ($string, $enc=null, $ret=null) {
static $enclist = array(
'UTF-8', 'ASCII',
'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3', 'ISO-8859-4', 'ISO-8859-5',
'ISO-8859-6', 'ISO-8859-7', 'ISO-8859-8', 'ISO-8859-9', 'ISO-8859-10',
'ISO-8859-13', 'ISO-8859-14', 'ISO-8859-15', 'ISO-8859-16',
'Windows-1251', 'Windows-1252', 'Windows-1254',
);
$result = false;
foreach ($enclist as $item) {
$sample = iconv($item, $item, $string);
if (md5($sample) == md5($string)) {
if ($ret === NULL) { $result = $item; } else { $result = true; }
break;
}
}
return $result;
}
来源:PHP