pradeepucer/web_dev_tools

各种PHP、JS、SQL、CSS和HTML网络开发工具

安装: 4

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

语言:JavaScript

类型:工具

v2.0 2023-05-09 09:37 UTC

This package is not auto-updated.

Last update: 2024-09-26 00:35:15 UTC


README

概览

各种PHP、JS、SQL、CSS和HTML网络开发工具

要求

  • PHP版本 5.4 或更高版本

安装

使用Composer安装包:composer require devpradeep/web_dev_tools

CSV读取器

这是一个简单的CSV读取器,可以读取CSV文件并将数据作为数组返回。它还支持根据提供的映射器映射数据,并允许通过偏移量和限制来控制读取的数据。

使用方法

$file_input = 'test.csv';
$csv = new CSV($file_input);
try {
    // Example 1: Read all records
    $data = $csv->read($file_input, []); 
    print('<pre>'.print_r($data,true).'</pre>');

    // Example 2: Read only 10 records
    $data = $csv->read($file_input, [], 1, 10); 
    print('<pre>'.print_r($data,true).'</pre>');

    // Example 3: Read only row number 10
    $data = $csv->read($file_input, [], '', '',10); 
    print('<pre>'.print_r($data,true).'</pre>');

    // Example 4: Read with mapper
    $map['id'] = 2;
    $map['desc'] = 12;
    $data = $csv->read($file_input, $map, '', '',10); 
    print('<pre>'.print_r($data,true).'</pre>');

    $file_output = 'log.csv';
    $csv_write = new CSV($file_output);

    $data[] = ['id' => 1, 'desc' => 'test1,455,5567 , 9900', 'link' => 'http://test1.com'];
	$data[] = ['id' => 2, 'desc' => 'test2,569697,454', 'link' => 'http://test1.com'];
	//Simple write
	//$file = $csv_write->write($file_output, $data);
	$map = [];
	$map['ID'] = 'id';
	$map['Link'] = 'link';
	$map['Description'] = 'desc';
	
	$formatter = array(
		'link' => function ( $v ) {
			$m = $v['link'] . '/test';
			return $m;
		},
	);
	//$file = $csv_write->write($file_output, $data, $map, $formatter)->file;
	$csv_write->write($file_output, $data, $map, $formatter)->download();

} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}