format.php
Table of Contents
Functions
- format() : string
- Format a template string using an external document.
Functions
format()
Format a template string using an external document.
format(string $template, array<string|int, mixed>|object|string $document[, string $prefix = '{{' ][, string $suffix = '}}' ][, string $separator = '.' ][, string|null $pattern = null ][, bool $preserveMissing = false ]) : string
This function supports different types of documents:
- If the document is a string, it replaces all placeholders with that string.
- If the document is an array or object, it replaces placeholders by key lookup.
Parameters
- $template : string
-
The string to format.
- $document : array<string|int, mixed>|object|string
-
Key-value pairs for placeholders.
- $prefix : string = '{{'
-
Placeholder prefix (default
{{
). - $suffix : string = '}}'
-
Placeholder suffix (default
}}
). - $separator : string = '.'
-
Separator used to traverse nested keys (default
.
). - $pattern : string|null = null
-
Optional full regex pattern to match placeholders (including delimiters).
- $preserveMissing : bool = false
Tags
Return values
string —The formatted string.