PHPackages                             azbosakov/param-string-placeholders - 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. [Templating &amp; Views](/categories/templating)
4. /
5. azbosakov/param-string-placeholders

ActiveLibrary[Templating &amp; Views](/categories/templating)

azbosakov/param-string-placeholders
===================================

Template string with configurable placeholder delimiters.

1.0.0(7y ago)014MITPHP

Since Mar 12Pushed 7y agoCompare

[ Source](https://github.com/AZBosakov/param-string-placeholders)[ Packagist](https://packagist.org/packages/azbosakov/param-string-placeholders)[ RSS](/packages/azbosakov-param-string-placeholders/feed)WikiDiscussions master Synced 3d ago

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

Class description
=================

[](#class-description)

A template string with a configurable placeholder delimiters. Can take forms like, eg.:

- 'aaa{PARAM}bbb' O:'{', C:'}'
- 'aaa{{PARAM}}bbb' O:'{{', C:'}}'
- 'aaa${PARAM}bbb' O:'${', C:'}'
- 'aaa%PARAM%bbb' O:'%', C:'%'
- 'aaabbb' O:'&lt;', C:'&gt;'

The placeholder structure is: E\* O P C, where:

- O: Opening delimiter
- P: Parameter name
- C: Closing delimiter
- E: Escape string

None of the O,C,E can be empty ''.

The placeholders are passed as a constructor arguments: ($template, $open, $close, $escape). If any of $open, $close or $escape is **null**, the default value for the class is used (class-wide defaults can be set with ::setDefaultDelimiters($open, $close, $escape)).

The string is scanned for the closest non-empty pairs of OPEN/CLOSE.

OPEN directly followed by CLOSE is not treated like a placeholder, but taken verbatim.

The string between the O/C pair is the PARAM name. It can contain anything, except, of cource, OPEN or CLOSE strings.

If the placeholder is directly preceded with 1 or more ESCAPE strings, any two of them are converted to single one. If the E string count is odd, the placeholder is escaped and taken as part of the string in the form OPC, without the last ESC.

Examples
========

[](#examples)

With O:'{', C:'}', E:'!'
------------------------

[](#with-o-c-e)

- {} : String '{}'
- {P} : Parameter with name 'P'
- !{P} : String '{P}'
- !!{P} : Double escape, string '!' + param 'P'
- !!!!!{P} : Two double escapes and a leftover one, escaping the placeholder: strings '!!' + '{P}'

So the template

'aaa{}{{P1}bbb!!!{P2}ccc!!{P3}ddd'

is parsed as:

'aaa{}{', @ P1, 'bbb!{P2}ccc!', @ P3, 'ddd'

With O:'%', C:'%', E:'%'
------------------------

[](#with-o-c-e-1)

- '%%%%%P%%%' is 2 double escapes (%%+%%) -&gt; string '%%' + param P + string '%%'

Methods
=======

[](#methods)

public function \_\_construct(string $template, ?string $open = null, ?string $close = null, ?string $escape = null)
--------------------------------------------------------------------------------------------------------------------

[](#public-function-__constructstring-template-string-open--null-string-close--null-string-escape--null)

If any of $open, $close or $escape is **null**, the default value for the class is used.

public function getPieces(): array
----------------------------------

[](#public-function-getpieces-array)

A debugging function - returns the pieces, to which the template string is split, with the placeholder pieces marked as '@ PHName'.

public function getDelimiters() : array
---------------------------------------

[](#public-function-getdelimiters--array)

Returns array \['open'=&gt;..., 'close'=&gt;..., 'escape'=&gt;...\]

public static function getDefaultDelimiters() : array
-----------------------------------------------------

[](#public-static-function-getdefaultdelimiters--array)

Returns array - the default delimiters for the class: \['open'=&gt;..., 'close'=&gt;..., 'escape'=&gt;...\]

public static function setDefaultDelimiters(?string $open = null, ?string $close = null, ?string $escape = null) : void
-----------------------------------------------------------------------------------------------------------------------

[](#public-static-function-setdefaultdelimitersstring-open--null-string-close--null-string-escape--null--void)

Set the default delimiters for the entire class. If any of them is **null**, use the hardcoded default.

public function getTemplate() : string (ParamStringInterface)
-------------------------------------------------------------

[](#public-function-gettemplate--string-paramstringinterface)

Get the template string passed to the constructor

public function withParam(string $name, $value) : self (ParamStringInterface)
-----------------------------------------------------------------------------

[](#public-function-withparamstring-name-value--self-paramstringinterface)

Clone the object and set the named param value.

public function getParam(string $name) (ParamStringInterface)
-------------------------------------------------------------

[](#public-function-getparamstring-name-paramstringinterface)

Get a parameter by name

public function withParams(array $params) : self (ParamStringInterface)
-----------------------------------------------------------------------

[](#public-function-withparamsarray-params--self-paramstringinterface)

Clone the object and set multiple params at once.

public function getParams() : array (ParamStringInterface)
----------------------------------------------------------

[](#public-function-getparams--array-paramstringinterface)

Get a snapshot of the parameters

public function \_\_toString() : string (ParamStringInterface)
--------------------------------------------------------------

[](#public-function-__tostring--string-paramstringinterface)

Complete example
================

[](#complete-example)

```
$ph = new Placeholders(
    'The answer is , !, !!, !!!, !!!!',
    '', '!'
);

$ph = $ph->withParams(['ans'=>42, 'a param'=>'XXX', 'also param'=>'YYY']);

"$ph" == 'The answer is 42, , !XXX, !, !!YYY';

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity60

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

2621d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9fe6053e1652840db4fa7c442c597345a10f0ea26276bfa2e732bbb32b7c519d?d=identicon)[azbosakov](/maintainers/azbosakov)

---

Top Contributors

[![AZBosakov](https://avatars.githubusercontent.com/u/44407115?v=4)](https://github.com/AZBosakov "AZBosakov (1 commits)")

---

Tags

templatetemplatingplaceholder

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/azbosakov-param-string-placeholders/health.svg)

```
[![Health](https://phpackages.com/badges/azbosakov-param-string-placeholders/health.svg)](https://phpackages.com/packages/azbosakov-param-string-placeholders)
```

###  Alternatives

[eftec/bladeone

The standalone version Blade Template Engine from Laravel in a single php file

8208.4M87](/packages/eftec-bladeone)[fenom/fenom

Fenom - excellent template engine for PHP

44395.5k19](/packages/fenom-fenom)[duncan3dc/blade

Use Laravel Blade templates without the full Laravel framework

160499.5k24](/packages/duncan3dc-blade)[anourvalar/office

Generate documents from existing Excel &amp; Word templates | Export tables to Excel (Grids)

24085.2k](/packages/anourvalar-office)[eftec/bladeonehtml

The standalone version Blade Template Engine from Laravel in a single php file

1018.1k5](/packages/eftec-bladeonehtml)

PHPackages © 2026

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