⇧
vadnica-logo
My Services About the Project Telegram O meni O meni

The htmlspecialchars() Function

The htmlspecialchars() function converts only the essential special characters into their corresponding HTML entities. This is crucial when outputting data entered by users (e.g., in comment sections), as it prevents anyone from injecting malicious JavaScript code that would otherwise execute in the browsers of other visitors.

Note for the simulator: Since some string functions (such as htmlentities, htmlspecialchars, and html_entity_decode) modify raw HTML characters, the browser in the output window might not always display the exact raw output (as it automatically processes it). To see how these functions truly behave, we highly recommend copying and testing the code locally in your IDE (e.g., PhpStorm, VS Code).

EXAMPLE
RESULT

Specific Characters

Predefined characters that get converted:

  1. & (ampersand): becomes &
  2. < (less than): becomes &lt;
  3. > (greater than): becomes &gt;
  4. " (double quote): becomes &quot;
  5. ' (single quote): becomes &#039; (only with ENT_QUOTES)