1. Go to this page and download the library: Download piplup/sanitize 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/ */
piplup / sanitize example snippets
use Piplup\Sanitize\Sanitize\TextSanitizer;
use Piplup\Sanitize\Escape\HtmlEscaper;
use Piplup\Sanitize\Kses\Kses;
use Piplup\Sanitize\Kses\AllowedHtml;
// Sanitize incoming data
$title = TextSanitizer::sanitizeTextField($_POST['title']);
$content = $_POST['content']; // raw, will be filtered on output
// Escape on the way out
echo '<h1>' . HtmlEscaper::escHtml($title) . '</h1>';
// Filter HTML through an allow-list
echo Kses::filter($content, AllowedHtml::post());
use Piplup\Sanitize\Sanitize\UrlSanitizer;
// For HTML attributes — output is HTML-encoded
UrlSanitizer::escUrl('https://example.com/?a=1&b=2');
// → 'https://example.com/?a=1&b=2'
// For HTTP redirects / storage — NOT HTML-encoded
UrlSanitizer::escUrlRaw('https://example.com/?a=1&b=2');
// → 'https://example.com/?a=1&b=2'
// Dangerous protocols rejected
UrlSanitizer::escUrl('javascript:alert(1)'); // → ''
// Custom protocol allow-list
UrlSanitizer::escUrl('myapp://deep-link', ['myapp']);
use Piplup\Sanitize\Sanitize\CssSanitizer;
// Default usage (Kses::filter() passes ['same-origin'] by default):
$clean = CssSanitizer::sanitize('cursor: url("/c.cur"), auto', ['same-origin']);
// Allow specific hosts for url(...) tokens:
$clean = CssSanitizer::sanitize($css, ['example.com', 'cdn.example.com']);
use Piplup\Sanitize\Escape\HtmlEscaper;
echo '<p>' . HtmlEscaper::escHtml($text) . '</p>';
echo '<input value="' . HtmlEscaper::escAttr($val) . '">';
echo '<textarea>' . HtmlEscaper::escTextarea($val) . '</textarea>';
// Undo escaping (do NOT echo result directly into HTML)
$decoded = HtmlEscaper::decodeEntities($encoded);
use Piplup\Sanitize\Escape\JsEscaper;
// Embed a PHP string in a JS string literal
$safe = JsEscaper::escJs($userInput);
// Use in template: <script>var msg = '<?= $safe
use Piplup\Sanitize\Kses\Kses;
use Piplup\Sanitize\Kses\AllowedHtml;
// Filter with a custom allow-list
$clean = Kses::filter($html, [
'a' => ['href' => true, 'title' => true],
'b' => [],
'em' => [],
]);
// Or use a preset
$clean = Kses::filter($html, AllowedHtml::post());