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]]);

// Filtering an UUID string
$value = '1a42403c-a29d-11ef-b864-0242ac120002';
$filtered = \TraderInteractive\Filter\UuidFilter::filter($value);
assert($value === $filtered);

// Filtering null values
$value = null;
$filtered = \TraderInteractive\Filter\UuidFilter::filter($value, true);
assert(null === $filtered);

// Filtering a nil UUID
$value = '00000000-0000-0000-0000-000000000000';
$filtered = \TraderInteractive\Filter\UuidFilter::filter($value, false, true);
assert($value === $filtered);

// Filtering for only UUID v4
$value = '1a42403c-a29d-41ef-b864-0242ac120002';
$filtered = \TraderInteractive\Filter\UuidFilter::filter($value, false, false, [4]);
assert($value === $filtered);

$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"