douxian1939 2015-10-30 19:06
浏览 117

字符串中不可打印的字符 - php

I am debugging a Drupal module (this module,webform_import,imports CSV data into the database) and getting some non-printable character causing error in the module. Here is my debugging code

if($v == 'semester'){
    dpm('found ' . $v);
}
else
{
    dpm('not found ' . $v);
    dpm(str_split($v));
}
dpm($v);

The variable $v is passed through following function

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;
}

This is the output of my debugging output of debugging code

According to the output, $v prints 'semester' but is not equal to string 'semester' and when converted into an array has 11 characters instead of 8. Please let me know if something is wrong with the _webform_import_csvfieldtrim function. Also, I have converted the CSV file's encoding to UTF-8.

Thank you.

  • 写回答

1条回答 默认 最新

  • dpo69086 2015-11-03 18:37
    关注

    The first 3 invisible characters are BOM. I changed the encoding to 'UTF-8 without BOM' and the module worked.

    评论

报告相同问题?

悬赏问题

  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题