PHPackages                             midweste/spf-lib-flattener - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. midweste/spf-lib-flattener

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

midweste/spf-lib-flattener
==========================

A library to flatten SPF records

114PHP

Since Apr 24Pushed 1y ago1 watchersCompare

[ Source](https://github.com/midweste/spf-lib-flattener)[ Packagist](https://packagist.org/packages/midweste/spf-lib-flattener)[ RSS](/packages/midweste-spf-lib-flattener/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

SPF (Sender Policy Framework) Flattening/Splitting Library
==========================================================

[](#spf-sender-policy-framework-flatteningsplitting-library)

No tests yet - Use at your own risk!
====================================

[](#no-tests-yet---use-at-your-own-risk)

Extension of the wonderful SPF-LIB library by mlocati ()

This PHP library allows you to:

- flatten a spf record into ips addresses
- split a flattened spf record into primary and child spf records
- get the SPF record from a domain name (parent lib mlocati/spf-lib)
- decode and validate the SPF record (parent lib mlocati/spf-lib)
- create the value of a TXT record (parent lib mlocati/spf-lib)
- check if domains and IP addresses satisfy the SPF records (parent lib mlocati/spf-lib)
- all the rest of what SPF-LIB library by mlocati () can do

Short introduction about SPF Flattener/Splitter
-----------------------------------------------

[](#short-introduction-about-spf-flattenersplitter)

This library is meant to address the issue where more than 10 lookups are present in a SPF record.

There are two parts:

- RecordFlattener - this class will flatten an spf record into an aggregated list of ips addresses
- RecordSplitter - takes a flattened record and split the ip addresses of into child records like spf1.domain.com spf2.domain.com

Because this is an extension to the wonderful SPF-LIB library by mlocati (), you can use this PHP library to build, validate, flatten, split, and check the SPF records.

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

[](#installation)

You can install this library with Composer:

```
composer require midweste/spf-lib-flattener
```

Usage
-----

[](#usage)

### Flattening an spf record from a domain name

[](#flattening-an-spf-record-from-a-domain-name)

```
namespace SpfLibFlattener;

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

$domain = 'example.com';
$spf = new SpfFlattener($domain);

$flatArray = $spf->toFlatArray();
$flatString = $spf->toFlatString();
$flatRecord = $spf->toFlatRecord();
```

### Flattening an spf record from an existing string record

[](#flattening-an-spf-record-from-an-existing-string-record)

```
namespace SpfLibFlattener;

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

$domain = 'example.com';

// Flatten a record by passing the record as a string
$record = 'v=spf1 include:example.com include:google.com -all';
$spf = SpfFlattener::createFromText($domain, $record);
$flatArray = $spf->toFlatArray();
$flatString = $spf->toFlatString();
$flatRecord = $spf->toFlatRecord();
```

### Splitting an spf record from an existing string record

[](#splitting-an-spf-record-from-an-existing-string-record)

```
namespace SpfLibFlattener;

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

$domain = 'example.com';
$spf = new SpfFlattener($domain);

$splitter = RecordSplitter::createFromTxt($spf->toFlatString());
$split = $splitter->split(512, 'spf#.' . $domain);

foreach ($split as $name => $r) {
    echo "name:$name record:$r" . PHP_EOL;
}
```

Do you want to really say thank you?
------------------------------------

[](#do-you-want-to-really-say-thank-you)

You can offer the original author that did all the heavy lifting (mlocati) a [monthly coffee](https://github.com/sponsors/mlocati) or a [one-time coffee](https://paypal.me/mlocati) 😉

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity15

Early-stage or recently created project

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/2df4ed3abb19aaf4771d0bc1b64769b21ae06929b32165560884f545fb80d0af?d=identicon)[midwestE](/maintainers/midwestE)

### Embed Badge

![Health badge](/badges/midweste-spf-lib-flattener/health.svg)

```
[![Health](https://phpackages.com/badges/midweste-spf-lib-flattener/health.svg)](https://phpackages.com/packages/midweste-spf-lib-flattener)
```

###  Alternatives

[arara/process

Provides a better API to work with processes on Unix-like systems

16861.7k2](/packages/arara-process)[ezsystems/ezautosave-ls

Content editing autosave extension for eZ Publish legacy

22423.2k3](/packages/ezsystems-ezautosave-ls)[copyleaks/php-plagiarism-checker

Copyleaks detects online plagiarism and checks content distribution. Use Copyleaks to find out if textual content is original and where it has been used before. This package shows how to integrate with the Copyleaks cloud to search for copyright infringement.

5066.4k](/packages/copyleaks-php-plagiarism-checker)[teknomavi/tcmb

T.C. Merkez Bankası üzerinden güncel döviz kurlarını çeker

7019.2k](/packages/teknomavi-tcmb)[silverstripe/multiform

SilverStripe forms with multiple steps, flow control and state persistence

3156.0k3](/packages/silverstripe-multiform)[kinglozzer/multiselectfield

A sortable multiple select field for managing many-to-many relations

1341.2k2](/packages/kinglozzer-multiselectfield)

PHPackages © 2026

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