PHP code example of aimeos / sanitizer

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

    

aimeos / sanitizer example snippets


use Aimeos\Sanitizer\Sane;

$input = '<p id="appConfig">Hello <strong>world</strong></p>'
    . '<script>alert(1)</script>';

$html = Sane::strict($input);

// <p>Hello <strong>world</strong></p>

use Aimeos\Sanitizer\Sane;

$input = '<svg><circle r="40"/></svg>'
    . '<script>alert(1)</script>'
    . '<a href="javascript:alert(2)" style="color:red"'
    . ' onclick="alert(3)">Click me</a>'
    . '<img src="data:image/png;base64,...">';

echo Sane::html($input);

// <a>Click me</a><img src="data:image/png;base64,...">

$html = Sane::html($input, [
    'iframe' => ['https://www.youtube.com/embed/'],
]);
bash
XDEBUG_MODE=off php vendor/bin/phpunit
php vendor/bin/phpstan analyze --no-progress --debug
bash
php tests/browser.php > /tmp/sanitizer-browser.html
bash
timeout 30s env XDEBUG_MODE=off php -d memory_limit=64M tests/benchmark.php