Introducing Blueprint – A PHP Library for Replacing Placeholders

Introducing Blueprint - A PHP Library for Replacing Placeholders

Wanted to share a small PHP library that I put together this morning. This makes it a bit easier to build and replace template strings in PHP.

This is based on a template string toolkit that I built in TypeScript earlier this year. I found it to be really useful, and needed it for another project, so I figured I’d make it a PHP library.

It doesn’t really fall within the “PHPNomad” architecture so I opted to put it in Novatorius instead. Excited to put this one to use!

$template = "Hello, {name}! Today is %%day%%.";

$definition1 = new PlaceholderDefinition('{', '}', ['name' => 'Alice']);
$definition2 = new PlaceholderDefinition('%%', '%%', ['day' => 'Monday']);

$processed = (new BlueprintProcessor($template))
    ->processDefinition($definition1)
    ->processDefinition($definition2);

echo $processed; // Outputs: "Hello, Alice! Today is Monday."

You can see it here: https://github.com/Novatorius/blueprint

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *