qobo/pattern

This package is abandoned and no longer maintained. No replacement package was suggested.

PHP library to manipulate text patterns with placeholders

v2.0.0 2017-10-09 08:48 UTC

This package is auto-updated.

Last update: 2023-04-08 19:44:42 UTC


README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

PHP library to manipulate text patterns with placeholders.

Install

Add a dependency on qobo/pattern to your project's composer.json like so:

{
	"require": {
		"qobo/pattern": "~1.0"
	}
}

or simply install from the command line like so:

$ composer require qobo/pattern:1.0.*

Usage

Here is the simplest example of usage:

<?php
require_once 'vendor/autoload.php';

$pattern = new \Qobo\Pattern\Pattern('Hello %%NAME%%');
print $pattern->parse(array('NAME' => 'Leonid'));
// result: Hello Leonid
?>

Here is an example with recursive parsing (the order of arguments doesn't matter):

<?php
require_once 'vendor/autoload.php';

$pattern = new \Qobo\Pattern\Pattern('Hello %%NAME%%');
print $pattern->parse(array('TITLE' => 'Mr.', 'NAME' => '%%TITLE%% Leonid'));
// result: Hello Mr. Leonid
?>

For more examples, see the unit tests.