String formatter supporting named arguments.
- PHP >= 5.3
- Import package namespace
use Nixiware\StringFormatter; - Format strings using the static method
format($str, $data)
$str- template string$data- values
Arguments are specified in the template string by placing them between double curly braces: {{argumentName}}.
Argument names can contain letters (a-z, A-Z), numbers (0-9) and underscore (_) character.
- Display a simple formatted string.
echo StringFormatter::format(
'It {{status}}!',
[
'status' => 'works'
]
);
Outputs: It works!
StringFormatter is available under the MIT license. See the LICENSE file for more info.