Escape HTML

Escape HTML special characters to prevent XSS attacks and ensure safe rendering.

Code

Utilities
echo "$str" | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#039;/g'

Parameters

The string containing HTML to escape.

Server

More Bash Snippets