PHPackages                             onesimus-systems/recoder - 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. onesimus-systems/recoder

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

onesimus-systems/recoder
========================

Simple shortcode library

1.0.0(10y ago)023[1 issues](https://github.com/onesimus-systems/Recoder/issues)MITPHPPHP &gt;=5.4.0

Since Nov 23Pushed 10y agoCompare

[ Source](https://github.com/onesimus-systems/Recoder)[ Packagist](https://packagist.org/packages/onesimus-systems/recoder)[ Docs](http://blog.onesimussystems.com)[ RSS](/packages/onesimus-systems-recoder/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

Recoder
=======

[](#recoder)

Recoder is a simple shortcode processor that uses Wordpress-like syntax. This library supports multiple formats such as:

```
[shortcode]
[shortcode argument="value"]
[shortcode truevalue argument=simple other="complex value"]
[shortcode]content[/shortcode]
[shortcode argument="value"]content[/shortcode]

```

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

[](#requirements)

- PHP &gt;= 5.4
- Multibyte string extension

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

[](#installation)

Composer:

```
composer require onesimus-systems/recoder

```

or in your composer.json:

```
(...)
"require": {
    "onesimus-systems/recoder": "^1.0.0"
}
(...)

```

and run `composer install`.

Usage
-----

[](#usage)

### Methods

[](#methods)

```
Recoder Recoder::_construct(string $open = null, string $close = null)
bool Recoder::register(string $shortcode, callable $func)
bool Recoder::registerAlias(string $shortcode, string $aliasedCode)
string Recoder::process(string $text [, mixed $... ])
null Recoder::unregister([string $shortcode = null])
null Recoder::setDelimiters(string $open, string $close = null)
```

### Basic usage

[](#basic-usage)

```
$sc = new Recoder();
$sc->register('name', function(array $options) { return $options['_code']; });
$sc->register('content', function(array $options) { return $options['_content']; });

$parsedText = $sc->process('[name]'); // Return: name
$parsedText = $sc->process('[content]Some content[/content]'); // Return: Some content
```

Shortcodes must be a string and be made up of letters, numbers, hyphens, or underscores. They cannot begin with an underscore. `register` and `registerAlias` will return false for an invalid code, true otherwise. Shortcodes may be overwritten by registering a new function. They can also be unregistered:

```
$sc->unregister('content'); // Unregister one code
$sc->unregister(); // Unregister all codes
```

### Aliasing Codes

[](#aliasing-codes)

```
$sc->registerAlias('newCode', 'aliasedCode'); // Now [newCode] will do the samething as [aliasedCode]
```

Aliased codes are resolved at processing time. This means, if the callback for the aliased code changes, the alias will resolve to the new callback instead of the original callback when it was registered.

### Using Arguments

[](#using-arguments)

```
$sc->register('list-args', function(array $options) {
    $r = [];
    foreach($options as $key => $val) {
        if ($key[0] !== '_') {
            $r []= "$key:$val";
        }
    }
    return implode(' & ', $r);
});

$parsedText = $sc->process('[list-args arg1=val1 arg2="Some value"]');
// Return: arg1:val1 & arg2:Some value
```

The options array contains the following library defined keys:

- `_raw` - Raw shortcode including content and ending tag
- `_content` - Text inside a paired shortcode, blank if shortcode is self-closing
- `_offset` - Offset in the text where the shortcode was found
- `_code` - The shortcode name itself
- `_length` - The length of the raw shortcode string

Any other keys are arguments from the shortcode. Keys beginning with an \_ are reserved for library use.

### Passing extra arguments to shortcode handlers

[](#passing-extra-arguments-to-shortcode-handlers)

```
$sc->register('code', function(array $options, $someObj) {
    return $someObj->someMethod();
});

$parsedText = $sc->process('[code]', $obj);
// Everything after the first argument is passed to the handlers
```

### Define your own syntax

[](#define-your-own-syntax)

```
$sc = new Recoder('{', '}'); // Code syntax is now {code arg=val}
```

Edge Cases
----------

[](#edge-cases)

- Unregistered shortcodes will be ignored and left as they are.
- Mismatching closing shortcode (`[code]content[/codex]`) will be ignored, opening tag will be interpreted as self-closing shortcode, eg. `[code]`.
- Overlapping shortcodes (`[code]content[inner][/code]content[/inner]`) are not supported and will be interpreted as self-closing, eg. `[code]content[inner][/code]`, second closing tag will be ignored.
- Nested shortcodes with the same name are also considered overlapping, which means that (assume that shortcode `[c]` returns its content) string `[c]x[c]y[/c]z[/c]` will be interpreted as `xyz[/c]` (first closing tag was matched to first opening tag). This can be solved by aliasing given shortcode handler name, because for example `[c]x[d]y[/d]z[/c]` will be processed correctly.

License
-------

[](#license)

Recoder is licensed under MIT.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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

3826d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8b0c8b2c3cadee570c224131bb905fcd14df14a41d0100796509d6a9df402618?d=identicon)[dragonrider23](/maintainers/dragonrider23)

---

Top Contributors

[![lfkeitel](https://avatars.githubusercontent.com/u/6619743?v=4)](https://github.com/lfkeitel "lfkeitel (6 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/onesimus-systems-recoder/health.svg)

```
[![Health](https://phpackages.com/badges/onesimus-systems-recoder/health.svg)](https://phpackages.com/packages/onesimus-systems-recoder)
```

###  Alternatives

[smart-crowd/simple-sms-drivers

Addition providers for simple SMS laravel package

101.0k](/packages/smart-crowd-simple-sms-drivers)

PHPackages © 2026

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