PHP code example of eugenecooper / purify
1. Go to this page and download the library: Download eugenecooper/purify 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/ */
eugenecooper / purify example snippets
$input = '<script>alert("Harmful Script");</script> <p style="a style" class="a-different-class">Test</p>';
$cleaned = Purify::clean($input);
echo $cleaned; // Returns '<p class="a-different-class">Test</p>'
$inputArray = [
'<script>alert("Harmful Script");</script> <p style="a style" class="a-different-class">Test</p>',
'<script>alert("Harmful Script");</script> <p style="a style" class="a-different-class">Test</p>',
];
$cleaned = Purfiy::clean($inputArray);
var_dump($cleaned); // Returns [0] => '<p class="a-different-class">Test</p>' [1] => '<p class="a-different-class">Test</p>'
$configuration = ['HTML.Allowed' => 'div,b,a[href]'];
$cleaned = Purify::clean($input, $configuration);
$configuration = ['HTML.Allowed' => 'div,b,a[href]'];
$cleaned = Purify::clean($input, $configuration, $merge = false);
$purifier = new HTMLPurifier();
Purify::setPurifier($purifier);
$settings = ['HTML.Allowed' => 'div,b,a[href]'];
$configuration = new HTMLPurifier_Config($settings);
Purify::setPurifierConfig($configuration);