From 2856b92aed85fdd90163c3a97a23f17256352778 Mon Sep 17 00:00:00 2001 From: Andrey Ryzhov Date: Wed, 16 May 2018 19:01:39 +0300 Subject: [PATCH] Add description. --- README.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6d3f050..4efc38a 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,26 @@ $instance = new PowerReplace(); $instance->it = 'eat'; $instance->and_it_2 = 'sleep'; $instance->replace($string); // equals to I know words: «eat» and «sleep» +``` +## Custom Functions -``` +Yup can add own function with replace rules. Markers and function are nor case sensitive. + +```php + +$string = 'Where is #word:leftAndRight(_)#?'; +// or the same +$string = 'Where is #WORD:LEFTANDRIGHT(_)#?'; + +$functionHolder = new FunctionsHolder(); + +// add custom function with name leftAndRight +$functionHolder->addFunction('leftAndRight', function ($string, $symbol = '') { + return $symbol . $string . $symbol; +}); +$instance = new PowerReplace($functionHolder); +$instance->word = 'center'; +$instance->replace($string); // Where is _center_? + +``` \ No newline at end of file