PHP code example of saeven / zf3-purifier

1. Go to this page and download the library: Download saeven/zf3-purifier 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/ */

    

saeven / zf3-purifier example snippets


class MyForm extends Laminas\Form\Form implements Laminas\InputFilter\InputFilterProviderInterface
{
    public function init()
    {
        $this->add([
            'name'    => 'text',
            'options' => [
                'label' => 'Text'
            ],
            'attributes' => [
                'type' => 'textarea',
            ],
        ]);
    }

    public function getInputFilterSpecification()
    {
        return [
            'text'  => [
                '

class MyInputFilter extends Laminas\InputFilter\InputFilter
{
    public function init()
    {
        $this->add([
            'name'     => 'text',
            '

 echo $this->htmlPurifier()->purify($foo->getText()) 

 echo $this->htmlPurifier($foo->getText()) 

return [
    'soflomo_purifier' => [
        'config' => [
            'HTML.Doctype' => 'HTML 4.01 Transitional'
        ],
    ],
];

return [
    'soflomo_purifier' => [
        'config' => [
            'HTML.DefinitionID' => 'my custom definitions',
        ], 
        'definitions' => [
            'HTML' => [
                'addAttribute' => [
                    [ 'a', 'target', 'Enum#_blank,_self,_target,_top' ]
                ],
            ],
        ],
    ],
];

class MyInputFilter extends Laminas\InputFilter\InputFilter
{
    public function init()
    {
        $this->add([
            'name'     => 'text',
            'ns' => [
                        'purifier_config' => [
                            'HTML.AllowedElements' => 'a, span'
                        ],
                    ],
                ],
            ],
        ]);
    }
}

$form = new MyForm();
$formElementManager = $serviceManager->get('FormElementManager');
$formElementManager->injectFactory($form);

// same goes for input filters
$inputFilter = new MyInputFilter();
$inputFilterManager = $serviceManager->get('InputFilterManager');
$inputFilterManager->populateFactory($inputFilter);

return [
    'soflomo_purifier' => [
        'standalone' => true,
    ],
];

return [
    'soflomo_purifier' => [
        'standalone'      => true,
        'standalone_path' => 'path/to/HTMLPurifier.standalone.php',
    ],
];