Htmlspecialchars FAQ

Usage from Address Bar

You can use direct access to this page from your browser address bar. Type the string that you need to encode or decode according to the following schema: https://md5calc.com/html/<TYPE:enc|dec>/<PHRASE> For example, to visit a page that contains encoded "<strong>", you can just visit the URL: https://md5calc.com/html/enc/<strong> Another cool feature is that you can specify "json" or "plain" mode in the URL and you will get only the encoded/decoded string in response.
Schema for this feature: https://md5calc.com/html/<TYPE:enc|dec>.<OUTPUT:plain|json>/<PHRASE> Example: https://md5calc.com/html/enc.plain/<strong> Will output: &lt;strong&gt;

Usage from JavaScript

We have removed the CORS restriction so you can use direct access to htmlspecialchars encode/decode in your JavaScript applications via AJAX.

Example:

var toEncode = '<strong>';
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
  if (xhr.readyState == 4 && xhr.status == 200) {
    console.log('String "'+toEncode+'"'
                +' encoded with htmlspecialchars is'
                +' "'+JSON.parse(xhr.response)+'"'
    );
  };
};
xhr.open('GET', 'https://md5calc.com/html/enc.json/'+encodeURIComponent(toEncode), true);
xhr.send();
Will output: String "<strong>" encoded with htmlspecialchars is "&lt;strong&gt;"

Usage from PHP

You can use direct access to this function in your applications.

PHP Example:

<?php
    $str = '<strong>';
    $url ='http://md5calc.sv/html/enc.plain/'.urlencode($str);
    $htmlencoded = file_get_contents($url);
    echo 'String "'.htmlspecialchars($str, ENT_QUOTES|ENT_IGNORE)
         .'" encoded with htmlspecialchars is "'
         .htmlspecialchars($htmlencoded, ENT_QUOTES|ENT_IGNORE).'"'
    ;
Will output: String "<strong>" encoded with htmlspecialchars is "&lt;strong&gt;"

How to do the same in PHP

<?php
    $str = '<script>';
    $htmlSpecialCharsEncodedStr = htmlspecialchars($str, ENT_QUOTES | ENT_IGNORE);
    $htmlSpecialCharsDecodedStr = htmlspecialchars_decode($htmlSpecialCharsEncodedStr, ENT_QUOTES);
    echo '<pre>';
    echo htmlspecialchars($str, ENT_QUOTES|ENT_IGNORE).PHP_EOL
         .' &rarr; '.htmlspecialchars($htmlSpecialCharsEncodedStr, ENT_QUOTES|ENT_IGNORE).PHP_EOL
         .' &rarr; '.htmlspecialchars($htmlSpecialCharsDecodedStr, ENT_QUOTES|ENT_IGNORE).PHP_EOL
       ;
    echo '</pre>';
Please read the privacy policy (agreement of the cookies usage, other websites embedded content, etc.). If you continue to use the site, we will assume that you agree with our privacy policy.
OkPrivacy Policy