Test htmlentities() PHP Function - Converting HTML Characters to Entities

When data needs to be presented in Web pages, HTML special characters must be well protected Otherwise, data well not be presented properly, or the Web will become corrupted. This page allows you to learn and test the htmlentities() function to protect embedded data in Web pages.

What are HTML special characters?

Most of you probably know that there are 3 basic HTML special characters reserved for HTML tags and entities: (<), (>) and (&).

But there are 2 more characters reserved for quoting tag attributes: (") and (').

If you don't protect those characters, your Web page will not work. Try the following HTML code, and see what happens:

Question: is it true that 23:59 < 00:00?<br>
Answer: <input value='it's true.'>

How to use and test htmlentities() PHP function?

htmlentities(string) is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are converted into these entities. For example

  • '&' (ampersand) becomes '&amp;'
  • '"' (double quote) becomes '&quot;'
  • ''' (single quote) becomes '&#039;' only when ENT_QUOTES is set. Not a default behavior.
  • '<' (less than) becomes '&lt;'
  • '>' (greater than) becomes '&gt;'

To help you learn and test htmlentities() function, FYIcenter.com has designed this online testing page. All you need to do is to enter the testing string in the form below and click the Start button. The converted string will be presented in the result area.


Popup Windows Tutorials

20 tutorials on different ways to create and test popup windows created in JavaScript: Page unload popups, Pop re-open on close, ...

200+ PHP Script Tutorials

Each tutorial answers one commonly asked PHP programming question with a short, but precise and clear PHP script.