Skip to content

Commit 8f9f056

Browse files
Update documentation to explain escaping special characters
Co-authored-by: henriquemoody <154023+henriquemoody@users.noreply.github.com>
1 parent ac22467 commit 8f9f056

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

docs/modifiers/FormatterModifier.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ The formatter name is converted to a formatter class name by:
2727

2828
Arguments after the formatter name (separated by `:`) are passed to the formatter's constructor.
2929

30+
### Escaping Special Characters
31+
32+
If your formatter arguments contain special characters (`:` or `|`), you can escape them with a backslash:
33+
34+
- Escape colons in arguments: `\:`
35+
- Escape pipes in arguments: `\|`
36+
37+
```
38+
{{placeholder|pattern:##\:##}} // Pattern with colon: 12:34
39+
{{placeholder|pattern:###\|###}} // Pattern with pipe: 123|456
40+
```
41+
3042
## Examples
3143

3244
### Date Formatting
@@ -92,6 +104,25 @@ echo $formatter->format('Phone: {{phone|pattern:(###) ###-####}}');
92104
// Output: Phone: (123) 456-7890
93105
```
94106

107+
### Escaping in Pattern Arguments
108+
109+
When your pattern contains special characters like `:` or `|`, escape them with a backslash:
110+
111+
```php
112+
$formatter = new PlaceholderFormatter([
113+
'time' => '1234',
114+
'value' => '123456',
115+
]);
116+
117+
// Pattern with escaped colon
118+
echo $formatter->format('Time: {{time|pattern:##\:##}}');
119+
// Output: Time: 12:34
120+
121+
// Pattern with escaped pipe
122+
echo $formatter->format('Value: {{value|pattern:###\|###}}');
123+
// Output: Value: 123|456
124+
```
125+
95126
### Metric Formatting
96127

97128
```php

0 commit comments

Comments
 (0)