PHPackages                             mattmezza/line-map - 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. mattmezza/line-map

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

mattmezza/line-map
==================

Do stuff for each line of text

3.0.1(8y ago)1271MITPHPPHP ^7.0

Since Dec 18Pushed 8y ago1 watchersCompare

[ Source](https://github.com/mattmezza/php-line-map)[ Packagist](https://packagist.org/packages/mattmezza/line-map)[ RSS](/packages/mattmezza-line-map/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (3)Dependencies (1)Versions (5)Used By (0)

PHP Line Map
============

[](#php-line-map)

[![Packagist](https://camo.githubusercontent.com/92810a5d758623cd9f3c45d73116ce49c3ea66e6a040c72ae337621de1dfde26/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6174746d657a7a612f6c696e652d6d61702e737667)](https://github.com/mattmezza/php-line-map) [![PHP from Packagist](https://camo.githubusercontent.com/b71e40a6493f03fb1201eb7750d7b821bae52c3a5bb77e268b1ad641aab54c7a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6d6174746d657a7a612f6c696e652d6d61702e737667)](https://github.com/mattmezza/php-line-map) [![GitHub license](https://camo.githubusercontent.com/f443a7753924ebaebc81bde89743e26707d1bbad4a66e3e98e7ac827483c2f46/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d6174746d657a7a612f7068702d6c696e652d6d61702e737667)](https://github.com/mattmezza/php-line-map/blob/master/license.md)

Maps a function through the lines of a file, line by line

Install it with `composer require mattmezza/line-map`

Use it like this:

```
$map = Map\CSV::fileNamed("example.csv");
$rows = $map->with(function ($row, $idx) {
    return array_merge([$idx + 1], $row);
})->get();
$header = $map->getHeader();
```

or

```
Map\Txt::fileNamed("lines.txt")->with(function ($line, $idx) {
    echo "$idx: $line";
});
```

TXT
===

[](#txt)

```
// the callback function - can be also an anonymous closure
$doStuff = function($line, $lineNumber) {
    return $lineNumber . ": " . $line;
};

// from a string variable
$text = "line 1
line2
line3";
$newLines = Map\Txt::string($text)->with($doStuff)->toArray();

// from a filename
$filename = "./somelines.txt";
$newLines = Map\Txt::fileNamed($filename)->with($doStuff)->toArray();

// from a file resource handle
$file = fopen($filename, "r");
$newLines = Map\Txt::file($file)->with($doStuff)->toArray();
```

CSV
===

[](#csv)

```
// the callback function - can be also an anonymous closure
$doStuff = function($row, $lineNumber, $headers) {
    echo $row[$headers[0]];
    return $row;
};

// from a string variable
$csv = "name,surname
John,Doe
Foo,Bar";
$newRows = Map\CSV::string($csv)->with($doStuff)->toArray();

// from a filename
$filename = "./somedata.csv";
$newRows = Map\CSV::fileNamed($filename)->with($doStuff)->toArray();

// from a file resource handle
$file = fopen($filename, "r");
$newRows = Map\CSV::file($file)->with($doStuff)->toArray();
```

##### example

[](#example)

Rapidly cycle through this CSV

```
name,username,email
Matt,mattmezza,mattmezza@gmail.com
```

for each line generate custom message replacing values using the following template

```
Hello {{name}},
your username is {{username}}.

```

send each message to the right user and collect some logs

```
$tpl = "Hello __name__,
your username is __username__.";
$logs = Map\CSV::fileNamed("file.csv")->with(function($row, $idx, $headers) use ($tpl) {
    $msg = $tpl;
    foreach ($headers as $header) {
        $msg = str_replace("{{".$header."}}", $row[$header], $msg);
    }
    return sendMail($row["email"]);
})->toArray();
```

###### Matteo Merola

[](#matteo-merola-mattmezzagmailcom)

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~30 days

Total

4

Last Release

3022d ago

Major Versions

1.0.0 → 2.0.02018-03-19

2.0.0 → 3.0.02018-03-20

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1915989?v=4)[Matteo Merola](/maintainers/mattmezza)[@mattmezza](https://github.com/mattmezza)

---

Top Contributors

[![mattmezza](https://avatars.githubusercontent.com/u/1915989?v=4)](https://github.com/mattmezza "mattmezza (8 commits)")

---

Tags

closurecollectioncsvforeachmapphptextfile

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mattmezza-line-map/health.svg)

```
[![Health](https://phpackages.com/badges/mattmezza-line-map/health.svg)](https://phpackages.com/packages/mattmezza-line-map)
```

###  Alternatives

[42coders/document-templates

Document template management package.

19940.0k](/packages/42coders-document-templates)[qipsius/tcpdf-bundle

A bundle to easily integrate TCPDF into Symfony

23749.5k](/packages/qipsius-tcpdf-bundle)[macopedia/magmi2

Magento Mass Importer 'Magmi' for Magento 2

11615.7k](/packages/macopedia-magmi2)[tarfin-labs/easy-pdf

Makes pdf processing easy.

1719.4k](/packages/tarfin-labs-easy-pdf)[akeneo-labs/excel-connector-bundle

Akeneo PIM Excel connector bundle

166.4k](/packages/akeneo-labs-excel-connector-bundle)

PHPackages © 2026

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