Escape output in a PHP template

Php

htmlspecialchars with the flags spelled out, because the defaults have changed between versions.

<?php
function e(?string $value): string {
    return htmlspecialchars($value ?? '', ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}
?>
<p><?= e($comment) ?></p>

More in PHP

Random picks