2015-10-30 53 views
0

我正在調試Drupal模塊(此模塊,webform_import,將CSV數據導入到數據庫中)並獲取一些導致模塊中出現錯誤的不可打印字符。這裏是我的調試代碼在字符串中的非打印字符-php

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

這傳遞是我調試 output of debugging code

的輸出根據輸出,$ V版畫「學期',但不等於字符串'學期',當轉換爲數組時有11個字符而不是8個。請讓我知道_webform_import_csvfieldtrim函數是否有問題。另外,我已將CSV文件的編碼轉換爲UTF-8。

謝謝。

回答

0

前3個不可見字符是BOM。我將編碼更改爲'沒有BOM的UTF-8',模塊工作。