PHP
Public
Safe HTML Escape Helper
A small PHP helper for escaping output in HTML templates.
#php
#security
#xss
#helper
PHP
<?php
function e(string $value): string
{
return htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}
$title = '<script>alert("xss")</script>';
echo '<h1>' . e($title) . '</h1>';
Notes
Escape output when rendering user-generated content into HTML.