以php爲主工作語言還不到2年的時間,實在被有些方法坑的不要不要的
http://www.php.net/manual/zh/function.fputcsv.php
int fputcsv ( resource $handle , array $fields [, string $delimiter = ',' [, string $enclosure = '"' ]] )
重點在第3個參數上,默認是雙引號
所有人都以爲它會給每個輸出的內容都會加上"",類似"1","2","3","4"
結果這個方法只有在輸出的內容有空格的時候纔會加引號 "1 2"," 3",4 這是什麼樣子的輸出
完全無法控制,根本不知道還有別的觸發時機沒,只能徹底放棄此方法
public function writeData($aData, $sDelimiter = ',', $sEnclosure = '"') {
foreach ($aData as $i => $value) {
$aData[$i] = mb_convert_encoding($value, $this->getToEncoding(), $this->getFromEncoding());
}
if (!isset($sEnclosure) || $sEnclosure === '') {
$sDataString = implode($sDelimiter, $aData) . $this->getEnterCode();
} else {
$sDataString = $sEnclosure.implode($sEnclosure.$sDelimiter.$sEnclosure, $aData) .$sEnclosure. $this->getEnterCode();
}
$bRet = fwrite($this->oFile, $sDataString);
return $bRet;
}
http://php.net/manual/zh/function.in-array.php
bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )
!!!!!!
一定要把那個$strict 設爲true啊,如果用默認的false,會死的很慘的,譬如官方下面舉得那個例子
!!!!!!
$array = array(
'egg' => true,
'cheese' => false,
'hair' => 765,
'goblins' => null,
'ogres' => 'no ogres allowed in this array'
);
// Loose checking -- return values are in comments
// First three make sense, last four do not
in_array(null, $array); // true
in_array(false, $array); // true
in_array(765, $array); // true
in_array(763, $array); // true
in_array('egg', $array); // true
in_array('hhh', $array); // true
in_array(array(), $array); // true
// Strict checking
in_array(null, $array, true); // true
in_array(false, $array, true); // true
in_array(765, $array, true); // true
in_array(763, $array, true); // false
in_array('egg', $array, true); // false
in_array('hhh', $array, true); // false
in_array(array(), $array, true); // false