Skip to main content

HTML Entity Converter & DOM Inspector

Rate this converter 0 of 0 ratings
Additional page content: Editable from the admin panel -> tools content.

Programmatic Code Snippets: Encode HTML Entities

How to implement Encode HTML Entities programmatically in Python, Node.js, PHP, and CLI
CLI & API Syntax
Escape HTML entities in Python
import html

s = '<div class="test">Toolbox24 & "Code"</div>'
escaped = html.escape(s)
print(escaped)
Encode HTML entities in JavaScript / Node.js
// npm install he
const he = require('he');

const s = '<div class="test">Toolbox24 & "Code"</div>';
console.log(he.encode(s));
Encode HTML entities in PHP
<?php
$s = '<div class="test">Toolbox24 & "Code"</div>';
echo htmlentities($s, ENT_QUOTES, 'UTF-8');
Encode HTML entities in PHP one-liner
php -r 'echo htmlentities($argv[1], ENT_QUOTES, "UTF-8");' '<div class="test">Toolbox24</div>'
Embed
Need this Html Entity Converter calculator on your website, lab portal, or research blog?
Free HTML Widget 100% Responsive Zero Cookie Tracking
Notice a calculation discrepancy, rounding error, or glitch?
Help us maintain 100% scientific precision and report any issues directly to engineering.