/** * @brief 字符串转码 * @param $content string 要转换的字符串 * @return string */ public function converContent($content) { if (IString::isUTF8($content) == false) { return iconv('GBK', 'UTF-8//IGNORE', $content); } return $content; }
/** * constructor,open the csv packet date file * @param string $csvFile csv file name * @param string $targetImagePath create csv image path */ public function __construct($csvFile, $targetImagePath) { if (!preg_match('|^[\\w\\-]+$|', basename($csvFile, '.csv'))) { throw new Exception('the csv file name must use english'); } if (!file_exists($csvFile)) { throw new Exception('the csv file is not exists!'); } if (!is_dir($targetImagePath)) { throw new Exception('the save csv image dir is not exists!'); } if (IString::isUTF8(file_get_contents($csvFile)) == false) { die("zip包里面的CSV文件编码格式错误,必须修改为UTF-8格式"); } //read csv file into dataLine array setlocale(LC_ALL, 'en_US.UTF-8'); $fileHandle = fopen($csvFile, 'r'); while ($tempRow = fgetcsv($fileHandle, 0, $this->separator)) { $this->dataLine[] = $tempRow; } $this->sourceImagePath = dirname($csvFile) . '/' . basename($csvFile, '.csv'); $this->targetImagePath = $targetImagePath; if (!$this->dataLine) { throw new Exception('the csv file is empty!'); } }