Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add documentation on multibyte encoding
- Loading branch information
Rick van der Staaij
committed
Jun 26, 2015
1 parent
b86c34d
commit 483d133
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Multibyte encoding | ||
|
||
To make sure your values get filtered correctly, we have to use the multi-byte (`mb_`) functionality from PHP. With | ||
this feature comes the ability to set the encoding format on the filter. | ||
|
||
```php | ||
$filter = new Particle\Filter\Filter; | ||
|
||
$filter->setEncodingFormat('utf-8'); // or another format if you like | ||
``` | ||
|
||
If you don't use the function above, the string adaptive functions from php will use the default value from your | ||
php.ini, which is most likely UTF-8. | ||
|
||
**Note:** Make sure that you set the encoding format on before you add any filter rules to the filter, otherwise the | ||
default encoding format will be used on the filter rules defined before that setEncodingFormat. | ||
|
||
### Converting values to a specific encoding format | ||
|
||
If you know data is coming in in a different encoding format than what you want to be working with, you can use the | ||
encode filter rule to convert the value. | ||
|
||
```php | ||
$filter->value('first_name')->encode('UTF-8')->upper(); | ||
``` | ||
|
||
### Using multibyte a regex | ||
|
||
If you want to use multi-byte encoded regex, the following php functions should be used: | ||
|
||
```php | ||
mb_regex_encoding('UTF-8'); | ||
``` | ||
|
||
These functions are not included in Particle\Filter as it might lead to unexpected behaviour. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters