PHP code example of moviet / panic-validator

1. Go to this page and download the library: Download moviet/panic-validator 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/ */

    

moviet / panic-validator example snippets


    use Moviet\Validator\Panic;
  use Moviet\Validator\Ival;

  $panic = new Panic;

  $nom = 'Smile'; 

  $getnom = $panic->case($nom)
                  ->rule(':alpha')
                  ->get(); 

  // var_dump : Smile
  

   $data = $panic->match(':doc','mydocument.xls');

   // Output : mydocument.xls
   

  $request = $_POST['String']; 

  $post = $panic->case($request)
                ->rule(':alNumSpace')
                ->throw(['Do not burn your finger, invalid !!']);
  

  $somePost = $panic->case($_POST['String'])
                    ->lang('En') // Optional
                    ->min(3)
                    ->max(100)
                    ->rule(':alphaSpace')
                    ->throw(['Please follow wakanda alphabets']);

   

   $anyPost = $panic->case(/*..Empty..*/)
                    ->rule(':alpha')
                    ->throw(['~ Gunakan angka atau spasi']);

  // Output : 'Please Fill Out The Form'
  

   $validUser = $panic->case($_POST['username'])
                      ->rule(':email')
                      ->throw(['Your username may error !!']);

   $validPass = $panic->case($_POST['password'])
                      ->auth(8)
                      ->throw(['Password minimum 8 characters']);
                      
   $tokenLog  = $panic->case($_POST['csrf'])
                      ->rule(':alphaNum')
                      ->get();

   $data = [$validUser, $validPass, $tokenLog];

   if ($panic->confirm($data) !== false) {

      // $_POST['username']
      // $_POST['password']
      // ...
   }
   

   $product = $panic->case($_GET['product'])
                    ->rule(':alNumSpace')
                    ->throw(['Do not only look, Please bo bo boy !!']);

   $tokenId = $panic->case($_GET['token_id'])
                    ->rule(':int')
                    ->throw(['Your token of course, invalid !!']);

   $validate = [$product, $tokenId]; 

   $entry = $panic->trust($_GET, $validate);
   
   // to retrieve data, please use array
   
   if ($entry !== false)
   $entry[0] // Equivalent $product
   $entry[1] // Equivalent $tokenId
   Next Next...
   

   $url = 'https://github.com/moviet/panic-validator';

   $data = $panic->filter(':url', $url); 

   // Output : https://github.com/moviet/panic-validator
    

   $myrule = $panic->case('My name is yoyo')
                   ->min(2)
                   ->max(20)
                   ->modify('/^[a-zA-Z 0-9]*$/')
                   ->throw(['What the hell something wrong ??']);

   // Return Boolen
   

   $string = 'Thanks you';

   $data = $panic->draft('/^[a-zA-Z@0-9_1-`-02-^"

   $data = $panic->verify($_POST['password'], 'DataPassword')
                 ->warn('Do not type password, please use Abcde !!'); 

   if ($panic->catch($data)) {

      // $_POST['password']
   }

   // Print $data => Do not type password, please use Abcde !!
   

   $stringHtml = '<script> If this is XSS </script>';

   $filterHtml = $panic->htmlSafe($stringHtml); 

   $html = $panic->htmlRaw($filterHtml); 

   // Output : <script> If this is XSS </script>
   

   $string = 'And thanos will go on';

   $encode = $panic->base64($string); 

   // Output : aOAIOAIHJSDH837287ksasjka983jsdhdsfsJHJAdsfd34dfSfb

   $decode = $panic->pure64($encode); 

   // Output : And thanos will go on
   
html
   <form method="POST" action="login.php" name="login">
   <table>
   <tbody>

   <tr><td>
    if (!$validUser)