PHP code example of traderinteractive / filter-strings

1. Go to this page and download the library: Download traderinteractive/filter-strings library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

traderinteractive / filter-strings example snippets


\TraderInteractive\Filter\Strings::filter($value);

$value = \TraderInteractive\Filter\Strings::concat('middle', 'begining_', '_end');
assert($value === 'begining_middle_end');

$value = \TraderInteractive\Filter\Strings::translate('active', ['inactive' => 'X', 'active' => 'A']);
assert($value === 'A');

$value = \TraderInteractive\Filter\Strings::explode('abc,def,ghi');
assert($value === ['abc', 'def', 'ghi']);

$value = \TraderInteractive\Filter\Strings::compress(' a string    with lots of    whitespace   ');
assert($value === 'a string with lots of whitespace');

$value = \TraderInteractive\Filter\Strings::compress(" a string\nwith lots\nof    \nnewlines\n   ", true);
assert($value === 'a string with lots of newlines');

$value = \TraderInteractive\Filter\Strings::redact('a string with some unwanted words', ['unwanted', 'words'], '*');
assert($value === 'a string with some ******** *****');

\TraderInteractive\Filter\Strings::stripTags('<div>a string with<br/>tags</div>', ' ');
assert($value === ' a string with tags ');

\TraderInteractive\Filter\Url::filter($value);

\TraderInteractive\Filter\Email::filter($value);

\TraderInteractive\Filter\Json::validate($value);

$value = '{ "string": "value", "array": [1, 2, 3] }';
\TraderInteractive\Filter\Json::parse($value);
assert($value === ['string' => 'value', 'array' => [1, 2, 3]]);

$value = "<root><outer><inner>value</inner></outer></root>";
$filtered = \TraderInteractive\Filter\XmlFilter::filter($value);
assert($value === $filtered);

$value = <<<XML
<?xml version="1.0"

$value = <<<XML
<?xml version="1.0"