PHPackages                             flsouto/md2php - 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. [CLI &amp; Console](/categories/cli)
4. /
5. flsouto/md2php

ActiveLibrary[CLI &amp; Console](/categories/cli)

flsouto/md2php
==============

Extracts php code blocks from markdown files and saves them nicely

1.0.0(9y ago)2221[1 PRs](https://github.com/flsouto/md2php/pulls)PHP

Since Oct 23Pushed 9y agoCompare

[ Source](https://github.com/flsouto/md2php)[ Packagist](https://packagist.org/packages/flsouto/md2php)[ RSS](/packages/flsouto-md2php/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

md2php
======

[](#md2php)

What is this
------------

[](#what-is-this)

This is a command line tool that allows you to extract php snippets from a markdown file and save these snippets in a directory. In order for a snippet to be matched and extracted from the markdown it must be in a code block starting with &lt;?php or &lt;?.

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

[](#installation)

Install this tool via composer:

```
composer require flsouto/md2php

```

Usage
-----

[](#usage)

First create a directory that will store all the snippets extracted from the markdown file:

```
$ mkdir snippets

```

Then call the extract program informing the markdown file to extract from and the directory to write to:

```
$ php vendor/flsouto/md2php/extract.php README.md ./snippets

```

As an example, I used the command above for processing the documentation of one of my repositories: [README.md](https://raw.githubusercontent.com/flsouto/array2options/master/README.md)

The output was:

```
Extracting snippet to ./snippets/01-array2options.php
Extracting snippet to ./snippets/02-selecting_option.php
Extracting snippet to ./snippets/03-using_associative_arrays.php
Extracting snippet to ./snippets/04-converting_datasets_options.php
Total snippets extracted: 4

```

Notice how the snippets are named in order of appearence in the document. Notice also that it is using the last heading matched before reaching the snippet as name for the file.

After doing that you can simply run an extracted snippet from the terminal itself:

```
$ php snippets/01-array2options.php

```

Final thoughts
--------------

[](#final-thoughts)

I find this tool useful when I am writing README documents such as this one because I can run the demonstration code blocks along the writing without having to be copying and pasting snippets all the time.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

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

Unknown

Total

1

Last Release

3491d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6875ef6cc1a877629f7133a3b7118a6d5871f5e04c02fa96e9831b4bd58c0926?d=identicon)[flsouto](/maintainers/flsouto)

---

Top Contributors

[![f4bi0](https://avatars.githubusercontent.com/u/6615387?v=4)](https://github.com/f4bi0 "f4bi0 (3 commits)")

---

Tags

command-linecodetoolmarkdownsnippets

### Embed Badge

![Health badge](/badges/flsouto-md2php/health.svg)

```
[![Health](https://phpackages.com/badges/flsouto-md2php/health.svg)](https://phpackages.com/packages/flsouto-md2php)
```

###  Alternatives

[symfony/console

Eases the creation of beautiful and testable command line interfaces

9.8k1.1B11.3k](/packages/symfony-console)[nunomaduro/collision

Cli error handling for console/command-line PHP applications.

4.6k331.8M8.5k](/packages/nunomaduro-collision)[nunomaduro/phpinsights

Instant PHP quality checks from your console.

5.6k10.8M426](/packages/nunomaduro-phpinsights)[nategood/commando

PHP CLI Commando Style

8123.3M38](/packages/nategood-commando)[marcocesarato/amwscan

AMWSCAN (Antimalware Scanner) is a php antimalware/antivirus scanner console script written in php for scan your project. This can work on php projects and a lot of others platform.

75317.8k1](/packages/marcocesarato-amwscan)[minicli/minicli

Experimental micro CLI framework for PHP

1.1k382.5k47](/packages/minicli-minicli)

PHPackages © 2026

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