承接 ruifernandees/csv-json-converter 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ruifernandees/csv-json-converter

Composer 安装命令:

composer require ruifernandees/csv-json-converter

包简介

A modern PHP CSV to JSON and JSON to CSV converter

README 文档

README

You can see the README in:

📄 Description

CSV/JSON Converter is a modern PHP component which abstracts the CSV to JSON and JSON to CSV conversion routine.

Install

Using Composer

$ composer require ruifernandees/csv-json-converter

💻 Usage

CSV -> JSON

This example is in examples/csvToJson.php

Code:

<?php

require __DIR__ . '/../vendor/autoload.php';

use RuiF\CsvToJson\FileFacade;

$filePath = __DIR__ . "/users.csv";

if (file_exists($filePath)) {
    $fileFacade = new FileFacade();

    /**
     * Is the line on the CSV file that the keys are (Like name, age, and city)
     */
    $lineOfCsvKeysOnTheFile = 1;

    /**
     * -1 if you want to get all lines of the CSV file (after the keys). 
     * If you want to limit, you can pass any number greater than zero
     * (See the examples below)
     */
    $limitOfLines = 1;

    /**
     * Is the start position after the keys that 
     * you want to consider when converting: 0 is the first position
     * (See the examples below)
     */
    $offset = 0;

    $json = $fileFacade->convertCsvToJson($filePath, $lineOfCsvKeysOnTheFile, $limitOfLines, $offset);
    
    echo $json;
} else {
    echo "The file doesn't exists";
}

Input file (users.csv):

name,age,city
Rui,18,Maceió
José,25,São Paulo
name age city
Rui 18 Maceió
José 25 São Paulo

Output (with limit 1 and offset 0):

[
    {
        "name": "Rui",
        "age": "18",
        "city": "Maceió"
    }
]

Output (with limit 1 and offset 1):

[
    {
        "name": "José",
        "age": "25",
        "city": "São Paulo"
    }
]

Output (with default limit and offset, getting all elements of the CSV file):

[
    {
        "name": "Rui",
        "age": "18",
        "city": "Maceió"
    },
    {
        "name": "José",
        "age": "25",
        "city": "São Paulo"
    }
]

You can save the JSON file with the following code:

$jsonFile = __DIR__ . "/users.json";

$fileOpen = fopen($jsonFile, "w");
fwrite($fileOpen, $json);

JSON -> CSV

This example is in examples/jsonToCsv.php

Code:

<?php

require __DIR__ . '/../vendor/autoload.php';

use RuiF\CsvToJson\FileFacade;

$filePath =  __DIR__ . '/users.json';

if (file_exists($filePath)) {
    $fileFacade = new FileFacade();
    $csv = $fileFacade->convertJsonToCsv($filePath);
    
    echo "Result:\n{$csv}";
} else {
    echo "The file doesn't exists";
}

Input file (users.json):

[
    {
        "name": "Rui",
        "age": "18",
        "city": "Maceió"
    },
    {
        "name": "José",
        "age": "25",
        "city": "São Paulo"
    }
]

Output:

name,age,city
Rui,18,Maceió
José,25,São Paulo
name age city
Rui 18 Maceió
José 25 São Paulo

You can save the CSV file with the following code:

$csvFile = __DIR__ . "/users.csv";

$fileOpen = fopen($csvFile, "w");
fwrite($fileOpen, $csv);

Run the tests

$ composer test

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information

ruifernandees/csv-json-converter 适用场景与选型建议

ruifernandees/csv-json-converter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 12 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 ruifernandees/csv-json-converter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ruifernandees/csv-json-converter 我们能提供哪些服务?
定制开发 / 二次开发

基于 ruifernandees/csv-json-converter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 17
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-12-23