A filtering implementation for verifying the contents of strings and some common formats of strings.
Requires PHP 7.0 or newer and uses composer to install further PHP dependencies. See the composer specification for more details.
filter-strings-php can be installed for use in your project using composer.
The recommended way of using this library in your project is to add a composer.json file to your project. The following contents would add filter-strings-php as a dependency:
composer require traderinteractive/filter-stringsThis filter verifies that the argument is a string. The second parameter can be set to true to allow
null values through without an error (they will stay null and not get converted to false). The last parameters specify the length bounds of the
string. The default bounds are 1+, so an empty string fails by default.
The following checks that $value is a non-empty string.
\TraderInteractive\Filter\Strings::filter($value);This filter concatenates the given $value, $prefix and $suffix and returns the resulting string.
$value = \TraderInteractive\Filter\Strings::concat('middle', 'begining_', '_end');
assert($value === 'begining_middle_end');This filter will accept a string value and return its translated value found in the given $valueMap.
$value = \TraderInteractive\Filter\Strings::translate('active', ['inactive' => 'X', 'active' => 'A']);
assert($value === 'A');This filter is essentially a wrapper around the built-in explode method
with the value first in order to work with the Filterer. It also defaults to using , as a delimiter. For example:
$value = \TraderInteractive\Filter\Strings::explode('abc,def,ghi');
assert($value === ['abc', 'def', 'ghi']);This filter verifies that the argument is a URL string according to
RFC2396. The second parameter can be set to true to allow
null values through without an error (they will stay null and not get converted to false).
The following checks that $value is a URL.
\TraderInteractive\Filter\Url::filter($value);This filter verifies that the argument is an email.
The following checks that $value is an email.
\TraderInteractive\Filter\Email::filter($value);Developers may be contacted at:
With a checkout of the code get Composer in your PATH and run:
./vendor/bin/phpcs
./vendor/bin/phpunitFor more information on our build process, read through out our Contribution Guidelines.
