The |quote modifier wraps string values with a configurable quote character (default: backtick `).
- Strings are wrapped with the quote character and internal occurrences are escaped
- Non-string values delegate to the next modifier
use Respect\StringFormatter\PlaceholderFormatter;
$formatter = new PlaceholderFormatter([
'name' => 'John',
'text' => 'Say `hello`',
'count' => 42,
]);
echo $formatter->format('User: {{name|quote}}');
// Output: User: `John`
echo $formatter->format('{{text|quote}}');
// Output: `Say \`hello\``
echo $formatter->format('{{count|quote}}');
// Output: 42 (delegated to next modifier)use Respect\StringFormatter\PlaceholderFormatter;
use Respect\StringFormatter\Modifiers\QuoteModifier;
use Respect\StringFormatter\Modifiers\StringifyModifier;
$formatter = new PlaceholderFormatter(
['name' => 'John'],
new QuoteModifier(new StringifyModifier(), "'"),
);
echo $formatter->format('{{name|quote}}');
// Output: 'John'| Parameters | Template | Output |
|---|---|---|
['name' => 'John'] |
{{name|quote}} |
`John` |
['t' => 'ab']` |
{{t|quote}} |
`a\`b` |
['n' => 42] |
{{n|quote}} |
42 |