use Psr\Http\Message\ServerRequestInterface; use Zend\Diactoros\ServerRequestFactory; use Zend\InputFilter\InputFilter; $request = ServerRequestFactory::fromGlobals(); $inputFilter = new InputFilter(); $inputFilter->add([ 'name' => 'username', 'required' => true, 'filters' => [ ['name' => 'StringTrim'], ], ]); $input = $inputFilter->getValues($request->getParsedBody()); $username = $input['username'];
use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Input\InputOption; use Zend\InputFilter\InputFilter; $input = new ArgvInput(); $inputFilter = new InputFilter(); $inputFilter->add([ 'name' => 'filename', 'required' => true, 'filters' => [ ['name' => 'StringTrim'], ['name' => 'StripTags'], ['name' => 'EscapeHtml'], ], ]); $input = $inputFilter->getValues($input->getArguments()); $filename = $input['filename'];In this example, we are using the `ArgvInput` class provided by the `symfony/console` package to retrieve command line arguments. We then create an `InputFilter` object to validate and sanitize the input data. The filter is configured to trim whitespace, strip HTML tags, and escape any HTML entities. We then call `getValues()` on the input filter to retrieve the sanitized data. In summary, the PHP Input Server provides a useful set of tools for working with input data in PHP applications. The package library used in these examples includes `zend-diactoros` and `symfony/console`.