PHPackages                             jupitern/file-parser - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. jupitern/file-parser

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

jupitern/file-parser
====================

read, filter, parse and format {csv, tsv, dsv, variable-length-delimited} and other txt files

1.2.0(1y ago)513.9k↓50%3MITPHPPHP &gt;=8.0

Since Feb 10Pushed 1y ago1 watchersCompare

[ Source](https://github.com/jupitern/file-parser)[ Packagist](https://packagist.org/packages/jupitern/file-parser)[ Docs](https://github.com/jupitern/file-parser)[ RSS](/packages/jupitern-file-parser/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)DependenciesVersions (9)Used By (0)

jupitern/file-parser
====================

[](#jupiternfile-parser)

#### PHP File Parser.

[](#php-file-parser)

read, filter, parse and format {csv, tsv, dsv, variable-length-delimited} from files or strings

Requirements
------------

[](#requirements)

PHP 8.0 or higher.

Installation
------------

[](#installation)

Include jupitern/file-parser in your project, by adding it to your composer.json file.

```
{
    "require": {
        "jupitern/file-parser": "1.*"
    }
}
```

Usage
-----

[](#usage)

```
Lets parse a csv from a string with contents (animal, category, count):
animal,type,count
crocodile,reptile,4
dolphin,mammal,0
duck,bird,2
koala,mammal,4
lion,mammal,5

lets parse the file with:
    - ignore the first line
    - convert encoding from ISO-9959-1 to UTF-8
    - convert lines to objects
    - remove animals with count 0
    - format the animal type to uppercase
    - group by type

$objectsArr = \Jupitern\Parser\FileParser::instance()
            ->fromString('animal,type,count
crocodile,reptile,4
dolphin,mammal,0
duck,bird,2
koala,mammal,4
lion,mammal,5', ',')
            ->setEncoding('ISO-8859-1', 'UTF-8')
            ->toObject(['animal', 'type', 'animalCount'])
            ->filter(function ($line, $lineNumber) {
                return $lineNumber > 1 && $line->animalCount > 0;
            })
            ->format('type', function ($val) {
                return strtoupper($val);
            })
            ->group(function ($line) {
                return $line->type;
            })
            ->parse();

        echo '';
        print_r($objectsArr);

/*
output:
Array
(
    [REPTILE] => Array
        (
            [0] => stdClass Object
                (
                    [animal] => crocodile
                    [type] => REPTILE
                    [animalCount] => 4
                )

        )

    [BIRD] => Array
        (
            [0] => stdClass Object
                (
                    [animal] => duck
                    [type] => BIRD
                    [animalCount] => 2
                )

        )

    [MAMMAL] => Array
        (
            [0] => stdClass Object
                (
                    [animal] => koala
                    [type] => MAMMAL
                    [animalCount] => 4
                )

            [1] => stdClass Object
                (
                    [animal] => lion
                    [type] => MAMMAL
                    [animalCount] => 5
                )

        )

)
*/

Given a csv file "filename.csv" with contents (animal, category, count):
animal,type,count
crocodile,reptile,4
dolphin,mammal,0
duck,bird,2
koala,mammal,4
lion,mammal,5

lets parse the file with:
    - ignore the first line
    - convert encoding from ISO-9959-1 to UTF-8
    - convert lines to objects
    - remove animals with count 0
    - format the animal type to uppercase
    - group by type

// read a file to array
$objectsArr = \Jupitern\Parser\FileParser::instance()
    ->fromFile('D:\\aaa.txt', ',')
    ->setEncoding('ISO-8859-1', 'UTF-8')
    ->toObject(['animal', 'type', 'animalCount'])
    ->filter(function ($line, $lineNumber) {
        return $lineNumber > 1 && $line->animalCount > 0;
    })
    ->format('type', function ($val) {
        return strtoupper($val);
    })
    ->group(function ($line) {
        return $line->type;
    })
    ->parse();

echo '';
print_r($objectsArr);

/*
output:
Array
(
    [REPTILE] => Array
        (
            [0] => stdClass Object
                (
                    [animal] => crocodile
                    [type] => REPTILE
                    [animalCount] => 4
                )

        )

    [BIRD] => Array
        (
            [0] => stdClass Object
                (
                    [animal] => duck
                    [type] => BIRD
                    [animalCount] => 2
                )

        )

    [MAMMAL] => Array
        (
            [0] => stdClass Object
                (
                    [animal] => koala
                    [type] => MAMMAL
                    [animalCount] => 4
                )

            [1] => stdClass Object
                (
                    [animal] => lion
                    [type] => MAMMAL
                    [animalCount] => 5
                )

        )

)
*/

For the same file lets parse with:
   - convert encoding from ISO-9959-1 to UTF-8
   - convert lines to arrays
   - remove animals with count 0
   - group by type

$objectsArr = \Jupitern\Parser\FileParser::instance()
    ->setFile("csv.txt", ',')
    ->setEncoding('ISO-8859-1', 'UTF-8')
    ->filter(function ($line, $lineNumber) {
        return $lineNumber > 1 && $line[2] > 0;
    })
    ->group(function ($line) {
        return $line[1];
    })
    ->parse();

echo '';
print_r($objectsArr);

/*
Output:
Array
(
    [reptile] => Array
        (
            [0] => Array
                (
                    [0] => crocodile
                    [1] => reptile
                    [2] => 4
                )

        )

    [bird] => Array
        (
            [0] => Array
                (
                    [0] => duck
                    [1] => bird
                    [2] => 2
                )

        )

    [mammal] => Array
        (
            [0] => Array
                (
                    [0] => koala
                    [1] => mammal
                    [2] => 4
                )

            [1] => Array
                (
                    [0] => lion
                    [1] => mammal
                    [2] => 5
                )

        )

)
*/

Given a dsv file "file.txt" with contents (empolyee number, birth date, monthly income):
01john doe        1980-01-01          923.5
01luis west       1976-01-01         1143.3
01madalena        1983-01-01         2173.6
02Jaqueline Wayne 1983-01-01         822.44
05luís manuel     1983-01-01        1323.52

lets parse the file doing:
    - convert encoding from ISO-9959-1 to UTF-8
    - convert lines to objects
    - format person name capitalize first letters
    - group by wage bellow or above 1000

$objectsArr = \Jupitern\Parser\FileParser::instance()
    ->setFile("test.txt")
    ->setEncoding('ISO-8859-1', 'UTF-8')
    ->each(function ($line){
        $obj = [];
        $obj['Number'] = mb_substr($line, 0, 2);
        $obj['Name'] = mb_substr($line, 2, 16);
        $obj['BirthDate'] = mb_substr($line, 18, 10);
        $obj['MonthlyIncome'] = (float)mb_substr($line, 28, 15);
        return (object)$obj;
    })
    ->format('Name', function ($val) {
        return ucwords($val);
    })
    ->group(function ($line) {
        return (float)$line->MonthlyIncome >= 1000 ? 'above 1000' : 'bellow 1000';
    })
    ->parse();

echo '';
print_r($objectsArr);

/*
Output:
Array
(
    [bellow 1000] => Array
        (
            [0] => stdClass Object
                (
                    [Number] => 01
                    [Name] => John Doe
                    [BirthDate] => 1980-01-01
                    [MonthlyIncome] => 923.5
                )

            [1] => stdClass Object
                (
                    [Number] => 02
                    [Name] => Jaqueline Wayne
                    [BirthDate] => 1983-01-01
                    [MonthlyIncome] => 822.44
                )

            [2] => stdClass Object
                (
                    [Number] => 05
                    [Name] => LuÃ­s Manuel
                    [BirthDate] =>  1983-01-0
                    [MonthlyIncome] => 1
                )

        )

    [above 1000] => Array
        (
            [0] => stdClass Object
                (
                    [Number] => 01
                    [Name] => Luis West
                    [BirthDate] => 1976-01-01
                    [MonthlyIncome] => 1143.3
                )

            [1] => stdClass Object
                (
                    [Number] => 01
                    [Name] => Madalena
                    [BirthDate] => 1983-01-01
                    [MonthlyIncome] => 2173.6
                )

        )

)
*/
```

ChangeLog
---------

[](#changelog)

v1.2.0

- min php version updated to 8.0
- code refactor for php8
- allow parse from string or file

v1

- initial release

Contributing
------------

[](#contributing)

- welcome to discuss a bugs, features and ideas.

License
-------

[](#license)

jupitern/file-parser is release under the MIT license.

You are free to use, modify and distribute this software

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 80% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~407 days

Recently: every ~713 days

Total

8

Last Release

530d ago

Major Versions

0.1.1 → 1.0.02017-02-10

0.1.3 → 1.1.02017-12-21

PHP version history (2 changes)0.1.0PHP &gt;=5.4

1.2.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/8205aca1dd2a7d1f98452950c3754b7430d16bcfe53494bfdf5c20d277d7776c?d=identicon)[jupitern](/maintainers/jupitern)

---

Top Contributors

[![advicente](https://avatars.githubusercontent.com/u/7566606?v=4)](https://github.com/advicente "advicente (4 commits)")[![jupitern](https://avatars.githubusercontent.com/u/4422374?v=4)](https://github.com/jupitern "jupitern (1 commits)")

---

Tags

csvdsvparserphpphp7txtvariable-length-delimitedcsvtsvFile parserdsvvariable-length-delimited

### Embed Badge

![Health badge](/badges/jupitern-file-parser/health.svg)

```
[![Health](https://phpackages.com/badges/jupitern-file-parser/health.svg)](https://phpackages.com/packages/jupitern-file-parser)
```

###  Alternatives

[maatwebsite/excel

Supercharged Excel exports and imports in Laravel

12.7k144.3M712](/packages/maatwebsite-excel)[league/csv

CSV data manipulation made easy in PHP

3.5k166.1M646](/packages/league-csv)[rap2hpoutre/fast-excel

Fast Excel import/export for Laravel

2.3k24.9M47](/packages/rap2hpoutre-fast-excel)[openspout/openspout

PHP Library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way

1.2k57.6M131](/packages/openspout-openspout)[faisalman/simple-excel-php

Easily parse / convert / write between Microsoft Excel XML / CSV / TSV / HTML / JSON / etc formats

582599.4k1](/packages/faisalman-simple-excel-php)[luchaninov/csv-file-loader

Load CSV &amp; TSV files and strings. Using generators to minimize memory usage

1134.9k](/packages/luchaninov-csv-file-loader)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
