qobo / pattern
PHP library to manipulate text patterns with placeholders
Installs: 27 139
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 15
Forks: 4
Open Issues: 0
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: ~4.3
- squizlabs/php_codesniffer: ~2.5
README
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.