PHP code example of rodrigojavornik / php-cleanup

1. Go to this page and download the library: Download rodrigojavornik/php-cleanup 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/ */

    

rodrigojavornik / php-cleanup example snippets


use PHPCleanup\Sanitize;

Sanitize::input()->sanitize(' <h1>Hello World</h1> ');//Hello World
Sanitize::trim()->captalize()->sanitize(' string    ');//String
Sanitize::trim()->lowercase()->sanitize(' MY name IS    ');//my name is
Sanitize::onlyNumbers()->sanitize(' abc1234');//1234

Sanitize::capitalize()->sanitaze('is wednesday my dudes');
//output: Is wednesday my dudes

Sanitize::captalizeAll()->sanitize('is wednesday my dudes');
//output: Is Wednesday My Dudes

Sanitize::dateTime()->sanitize('2023-08-10 10:15:00')->getTimestamp();
Sanitize::dateTime()->sanitize('2023-08-10 10:15:00asfasdfdsf')->getTimestamp();
Sanitize::dateTime()->sanitize('2023-08-10 10:15:00 ')->getTimestamp();
Sanitize::dateTime('d/m/Y H:i:s')->sanitize(' 10/08/2023 10:15:00')->getTimestamp();
//output: DateTime object 

Sanitize::email()->sanitize('email#[email protected] ');
//output: email#[email protected]

Sanitize::email()->sanitize('[email protected]');
//output: [email protected]

Sanitize::email()->sanitize('email1@domain().com');
//output: [email protected]

Sanitize::escape()->sanitize('<script>is wednesday my dudes &</script>')
//output: &lt;script&gt;is wednesday my dudes &amp;&lt;/script&gt;

Sanitize::formatNumber(2, '.')->sanitize('123321123sdfasdf');
//output:123321123.00
Sanitize::formatNumber(2, ',')->sanitize('123321123sdfasdf');
//output:123321123,00
Sanitize::formatNumber(2, ',', '.')->sanitize('123321123sdfasdf');
//output:123.321.123,00
Sanitize::formatNumber(2, '.', ',')->sanitize('123321123sdfasdf');
//output:123,321,123.00
Sanitize::formatNumber(3, '.', ',')->sanitize('1987.7')
//output:1,987.700

Sanitize::input()->sanitize(' <script>hello world &</script> ');
//output: hello world &

$list = [
	'name' => ' carlos alberto ',
	'age' => '23r',
	'email' => ' ¨[email protected] '
];

$result = Sanitize::keys([
	'name' => Sanitize::input()->uppercase(),
	'age' => Sanitize::input()->onlyNumbers(),
	'email' => Sanitize::input()->email()
])->sanitize($list);
/* output:
array(3) {
  ["name"]=>
  string(14) "CARLOS ALBERTO"
  ["age"]=>
  string(2) "23"
  ["email"]=>
  string(15) "[email protected]"
}*/ 

Sanitize::lowercase()->sanitize('THE LIBRARY OF ALEXANDRIA');
//output: the library of alexandria

Sanitize::money()->sanitize('123456');
//output: $123,654.00

Sanitize::money('pt_br')->sanitize('1236.54');
//output: R$ 1.236,54

Sanitize::onlyAlpha()->sanitize('Home ç 1@#$%¨(873469');
//output: Home

Sanitize::onlyAlpha('ç', '1', ' ')->sanitize('Home ç 123456');
//output: Home ç 1

Sanitize::onlyLatinAlpha()->sanitize('Home ç 1@#$%¨(873469');
//output: Home ç ¨

Sanitize::onlyLatinAlpha()->sanitize('Home ç 123456');
//output: Home ç 

Sanitize::onlyNumbers()->sanitize('Home ç 1@#$%¨(873469');
//output: 1873469

Sanitize::onlyNumbers()->sanitize('Home ç 123456');
//output: 123456 

Sanitize::removeAccentedCharacters()->sanitize("Qu'á çà, qu'á là, mon ami?");
//output: Qu'a ca, qu'a la, mon ami?

Sanitize::removeAccentedCharacters()->sanitize("Águas passadas não movem moinhos.")
//output: Aguas passadas nao movem moinhos.

Sanitize::stripTags()->sanitize('<html><h1>welcome</h1></html>');
//output: welcome

Sanitize::stripTags('<h1>')->sanitize('<html><h1>welcome</h1></html>')
//output: <h1>welcome</h1>

Sanitize::uppercase()->sanitize(' blablabla ');
//output: blablabla

Sanitize::uppercase()->sanitize('home');
//output: HOME