1. Go to this page and download the library: Download tobento/app-html-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/ */
tobento / app-html-sanitizer example snippets
use Tobento\App\AppFactory;
use Tobento\App\HtmlSanitizer\HtmlSanitizerInterface;
use Tobento\App\HtmlSanitizer\HtmlSanitizersInterface;
// Create the app
$app = (new AppFactory())->createApp();
// Add directories:
$app->dirs()
->dir(realpath(__DIR__.'/../'), 'root')
->dir(realpath(__DIR__.'/../app/'), 'app')
->dir($app->dir('app').'config', 'config', group: 'config')
->dir($app->dir('root').'public', 'public')
->dir($app->dir('root').'vendor', 'vendor');
// Adding boots:
$app->boot(\Tobento\App\HtmlSanitizer\Boot\HtmlSanitizer::class);
$app->booting();
// Implemented interfaces:
$htmlSanitizer = $app->get(HtmlSanitizerInterface::class);
$htmlSanitizers = $app->get(HtmlSanitizersInterface::class);
// Run the app
$app->run();
<!-- Using the default -->
<?= $view->sanitizeHtml($html)
use function Tobento\App\HtmlSanitizer\{sanitizeHtml, sanitizeHtmlFor};
$safeHtml = sanitizeHtml($html);
// Or using a specific sanitizer
$safeHtml = sanitizeHtml(html: $html, sanitizer: 'name');
$safeHtml = sanitizeHtmlFor('h1', $html, 'named');
// Or using a specific sanitizer
$safeHtml = sanitizeHtmlFor(element: 'h1', html: $html, sanitizer: 'name');
use Tobento\App\HtmlSanitizer\Purifier;
use function Tobento\App\{directory};
return [
'sanitizers' => [
'default' => new Purifier\HtmlSanitizerFactory([
'Cache.SerializerPath' => directory('app').'storage/html-sanitizer/purifier',
'Cache.SerializerPermissions' => 0755,
'Attr.AllowedFrameTargets' => ['_blank'],
]),
],
];
use Tobento\App\Boot;
use Tobento\App\HtmlSanitizer\HtmlSanitizerFactoryInterface;
use Tobento\App\HtmlSanitizer\HtmlSanitizerInterface;
use Tobento\App\HtmlSanitizer\HtmlSanitizersInterface;
class HtmlSanitizersBoot extends Boot
{
public const BOOT = [
// you may ensure the sanitizer boot.
\Tobento\App\HtmlSanitizer\Boot\HtmlSanitizer::class,
];
public function boot()
{
// you may use the app on method to add only if requested:
$app->on(
HtmlSanitizersInterface::class,
static function(HtmlSanitizersInterface $htmlSanitizers) {
$htmlSanitizers->add(
name: 'custom',
sanitizer: $sanitizer, // HtmlSanitizerFactoryInterface|HtmlSanitizerInterface
);
}
);
}
}
app/config/html_sanitizer.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.