laminas/laminas-filter
A collection of reusable data filters for PHP apps. Provides string and numeric normalization, file and HTML filters, and a plugin manager to compose filter chains. Useful for sanitizing and transforming input consistently across Laminas and other frameworks.
In addition to the standard set of filters, there are several classes specific to filtering word strings.
TIP: New Behaviour since Version 3
The filter will now treat numbers as a word boundary.
For example ThisHas4Words will filter to This-Has-4-Words.
This filter modifies a given string such that CamelCaseWords are converted to Camel-Case-Words.
$filter = new Laminas\Filter\Word\CamelCaseToDash();
print $filter->filter('ThisIsMyContent');
The above example returns This-Is-My-Content.
There are no additional options for Laminas\Filter\Word\CamelCaseToDash.
TIP: New Behaviour since Version 3
The filter will now treat numbers as a word boundary.
For example ThisHas4Words with the default separator will filter to This Has 4 Words
This filter modifies a given string such that CamelCaseWords are converted to Camel Case Words.
$filter = new Laminas\Filter\Word\CamelCaseToSeparator();
print $filter->filter('ThisIsMyContent');
The above example returns This Is My Content.
The following options are supported for Laminas\Filter\Word\CamelCaseToSeparator:
| Option | Description | Type | Default |
|---|---|---|---|
separator |
A separator character | string |
' ' (space) |
$filter = new Laminas\Filter\Word\CamelCaseToSeparator(['separator' => ':']);
print $filter->filter('ThisIsMyContent');
The above example returns This:Is:My:Content.
TIP: New Behaviour since Version 3
The filter will now treat numbers as a word boundary.
For example ThisHas4Words will filter to This_Has_4_Words
This filter modifies a given string such that CamelCaseWords are converted to
Camel_Case_Words.
$filter = new Laminas\Filter\Word\CamelCaseToUnderscore();
print $filter->filter('ThisIsMyContent');
The above example returns This_Is_My_Content.
There are no additional options for Laminas\Filter\Word\CamelCaseToUnderscore.
This filter modifies a given string such that words-with-dashes are converted
to WordsWithDashes.
$filter = new Laminas\Filter\Word\DashToCamelCase();
print $filter->filter('this-is-my-content');
The above example returns ThisIsMyContent.
There are no additional options for Laminas\Filter\Word\DashToCamelCase:
This filter modifies a given string such that words-with-dashes are converted
to words with dashes.
$filter = new Laminas\Filter\Word\DashToSeparator();
print $filter->filter('this-is-my-content');
The above example returns this is my content.
The following options are supported for Laminas\Filter\Word\DashToSeparator:
| Option | Description | Type | Default |
|---|---|---|---|
separator |
A separator character | string |
' ' (space) |
$filter = new Laminas\Filter\Word\DashToSeparator(['separator' => '+']);
print $filter->filter('this-is-my-content');
The above example returns this+is+my+content.
This filter modifies a given string such that words-with-dashes are converted
to words_with_dashes.
$filter = new Laminas\Filter\Word\DashToUnderscore();
print $filter->filter('this-is-my-content');
The above example returns this_is_my_content.
There are no additional options for Laminas\Filter\Word\DashToUnderscore.
This filter modifies a given string such that words with separators are
converted to WordsWithSeparators.
$filter = new Laminas\Filter\Word\SeparatorToCamelCase();
print $filter->filter('this is my content');
The above example returns ThisIsMyContent.
The following options are supported for Laminas\Filter\Word\SeparatorToCamelCase:
| Option | Description | Type | Default |
|---|---|---|---|
separator |
A separator character | string |
' ' (space) |
$filter = new Laminas\Filter\Word\SeparatorToCamelCase(['separator' => ':']);
print $filter->filter('this:is:my:content');
The above example returns ThisIsMyContent.
This filter modifies a given string such that words with separators are
converted to words-with-separators.
$filter = new Laminas\Filter\Word\SeparatorToDash();
print $filter->filter('this is my content');
The above example returns this-is-my-content.
The following options are supported for Laminas\Filter\Word\SeparatorToDash:
| Option | Description | Type | Default |
|---|---|---|---|
separator |
A separator character. | string |
' ' (space) |
$filter = new Laminas\Filter\Word\SeparatorToDash(['separator' => ':']);
print $filter->filter('this:is:my:content');
The above example returns this-is-my-content.
This filter modifies a given string such that words with separators are
converted to words-with-separators.
$filter = new Laminas\Filter\Word\SeparatorToSeparator();
print $filter->filter('this is my content');
The above example returns this-is-my-content.
The following options are supported for Laminas\Filter\Word\SeparatorToSeparator:
| Option | Description | Type | Default |
|---|---|---|---|
searchSeparator |
The search separator character | string |
' ' (space) |
replaceSeparator |
The replacement separator character | string |
- |
$filter = new Laminas\Filter\Word\SeparatorToSeparator([
'search_separator' => ':',
'replacement_separator' => '+',
]);
print $filter->filter('this:is:my:content');
The above example returns this+is+my+content.
This filter modifies a given string such that words_with_underscores are
converted to WordsWithUnderscores.
$filter = new Laminas\Filter\Word\UnderscoreToCamelCase();
print $filter->filter('this_is_my_content');
The above example returns ThisIsMyContent.
There are no additional options for Laminas\Filter\Word\UnderscoreToCamelCase.
This filter modifies a given string such that words_with_underscores are
converted to words with underscores.
$filter = new Laminas\Filter\Word\UnderscoreToSeparator();
print $filter->filter('this_is_my_content');
The above example returns this is my content.
The following options are supported for Laminas\Filter\Word\UnderscoreToSeparator:
| Option | Description | Type | Default |
|---|---|---|---|
separator |
A separator character | string |
' ' (space) |
$filter = new Laminas\Filter\Word\UnderscoreToSeparator(['separator' => '+']));
print $filter->filter('this_is_my_content');
The above example returns this+is+my+content.
This filter modifies a given string such that words_with_underscores are
converted to words-with-underscores.
$filter = new Laminas\Filter\Word\UnderscoreToDash();
print $filter->filter('this_is_my_content');
The above example returns this-is-my-content.
There are no additional options for Laminas\Filter\Word\UnderscoreToDash.
This filter modifies a given string such that words_with_underscores are
converted to wordsWithUnderscores.
$filter = new Laminas\Filter\Word\UnderscoreToStudlyCase();
print $filter->filter('this_is_my_content');
The above example returns thisIsMyContent.
There are no additional options for Laminas\Filter\Word\UnderscoreToStudlyCase.
How can I help you explore Laravel packages today?