企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[Xunsearch PHP-SDK](http://www.xunsearch.com) v1.4.8 API 参考文档 # XSCsvDataSource [All Packages](#)| [属性](#)| [方法(函数)](#) | 包 | [XS.util](#) | |-----|-----| | 继承关系 | class XSCsvDataSource »[XSDataSource](#) | | 版本 | 1.0.0 | | 源代码 | [sdk/php/util/XSDataSource.class.php](https://github.com/hightman/xunsearch/blob/master/sdk/php/util/XSDataSource.class.php) | CSV 数据源可在文件开头指定字段(必须是有效字段), 否则将默认按照 [XS](#) 项目字段顺序填充 ### Public 属性 [隐去继承来的属性](#) | 名称 | 类型 | 描述 | 定义于 | |-----|-----|-----|-----| | [invalidLines](#) | | | XSCsvDataSource | ### Protected 属性 [隐去继承来的属性](#) | 名称 | 类型 | 描述 | 定义于 | |-----|-----|-----|-----| | [arg](#) | | | [XSDataSource](#) | | [inCli](#) | | | [XSDataSource](#) | | [type](#) | | | [XSDataSource](#) | ### Public 方法 [隐去继承来的方法](#) | 名称 | 描述 | 定义于 | |-----|-----|-----| | [__construct()](#) | 构造函数 | [XSDataSource](#) | | [getCharset()](#) | 取得数据源的准确字符集 | [XSDataSource](#) | | [getData()](#) | 从数据源中提取一条数据 | [XSDataSource](#) | | [instance()](#) | 取得数据源对象实例 | [XSDataSource](#) | ### Protected 方法 [隐去继承来的方法](#) | 名称 | 描述 | 定义于 | |-----|-----|-----| | [deinit()](#) | | XSCsvDataSource | | [getDataList()](#) | | XSCsvDataSource | | [init()](#) | | XSCsvDataSource | ### 属性明细 invalidLines属性 public **$invalidLines**; ### 方法明细 deinit()方法 <table class="summaryTable"><tr><td colspan="3"><div class="signature2">protected void <b>deinit</b>()</div></td></tr></table> **源码:**[sdk/php/util/XSDataSource.class.php#L384](https://github.com/hightman/xunsearch/blob/master/sdk/php/util/XSDataSource.class.php#L384) (**[显示](#)**) `protected function deinit() {     if ($this->fd) {         fclose($this->fd);         $this->fd = null;     } }` getDataList()方法 <table class="summaryTable"><tr><td colspan="3"><div class="signature2">protected void <b>getDataList</b>()</div></td></tr></table> **源码:**[sdk/php/util/XSDataSource.class.php#L392](https://github.com/hightman/xunsearch/blob/master/sdk/php/util/XSDataSource.class.php#L392) (**[显示](#)**) `protected function getDataList() {     if (($item = fgetcsv($this->fd, 0, $this->delim)) === false) {         if ($this->inCli) {             echo "INFO: reach end of file or error occured, total lines: " . $this->line . "\n";         }         return false;     }     $this->line++;     if (count($item) === 1 && is_null($item[0])) {         if ($this->inCli) {             echo "WARNING: invalid csv line #" . $this->line . "\n";         }         $this->invalidLines++;         return $this->getDataList();     }     return array($item); }` init()方法 <table class="summaryTable"><tr><td colspan="3"><div class="signature2">protected void <b>init</b>()</div></td></tr></table> **源码:**[sdk/php/util/XSDataSource.class.php#L368](https://github.com/hightman/xunsearch/blob/master/sdk/php/util/XSDataSource.class.php#L368) (**[显示](#)**) `protected function init() {     $file = $this->arg;     if (empty($file) && $this->inCli) {         echo "WARNING: input file not specified, read data from <STDIN>\n";         $file = 'php://stdin';     }     if (!($this->fd = fopen($file, 'r'))) {         throw new XSException("Can not open input file: '$file'");     }     $this->line = 0;     if (isset($_SERVER['XS_CSV_DELIMITER'])) {         $this->delim = $_SERVER['XS_CSV_DELIMITER'];     } }` Copyright © 2008-2011 by [杭州云圣网络科技有限公司](http://www.xunsearch.com) All Rights Reserved.