【问题标题】:non printable characters in a string - php字符串中的不可打印字符 - php
【发布时间】: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。

谢谢。

【问题讨论】:

    标签: php character-encoding


    【解决方案1】:

    前 3 个不可见字符是 BOM。我将编码更改为 'UTF-8 without BOM' 并且模块工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多