【发布时间】:2015-11-04 02:37:29
【问题描述】:
我正在调试一个 Drupal 模块(此模块,webform_import,将 CSV 数据导入数据库)并得到一些导致模块错误的不可打印字符。这是我的调试代码
if($v == 'semester'){
dpm('found ' . $v);
}
else
{
dpm('not found ' . $v);
dpm(str_split($v));
}
dpm($v);
变量$v通过以下函数传递
function _webform_import_csvfieldtrim($value) {
$value = trim($value);
// Strip off the beginning and ending quotes if necessary.
$value = preg_replace('/^".*"$/', '', $value);
// Remove control characters. Some editors add invalid EOL chars.
// fgetcsv does not handle unicode characters therefore we replace them
// manually. See http://bugs.php.net/bug.php?id=31632.
$value = str_replace('\x00..\x1F\xfe\xff', '', $value);
//$value = str_replace('/[\x00-\x1F\x80-\xFF]/', '', $value);
return $value;
}
根据输出,$v 打印 'semester' 但不等于字符串 'semester' 并且在转换为数组时有 11 个字符而不是 8 个字符。如果 _webform_import_csvfieldtrim 函数有问题,请告诉我。另外,我已将 CSV 文件的编码转换为 UTF-8。
谢谢。
【问题讨论】: