CodShot
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.

Snippet actions

CodShot user
CodShot user
Updated: 2026-06-03 14:05
Public snippets
0
Forks
CodShot AI Help
Ask about CodShot features, plans, workspace, AI limits, referrals, and public help topics.
Hi! I can help you understand how CodShot works. What would you like to know?
For account-specific or sensitive issues, please open a support ticket. Open support