-1

I've got an mySQL database and I'm using htmlspecial chars to format text before insertion... I've got: $firstname= htmlspecialchars("O'brian", ENT_QUOTES,'UTF-8');

And if I echo $firstname; I get O'brian

How can I convert the value back to normal text?

dlofrodloh
  • 1,728
  • 3
  • 23
  • 44

3 Answers3

4

Use the htmlspecialchars_decode function.

htmlspecialchars_decode($firstname, ENT_QUOTES);
slapyo
  • 2,979
  • 1
  • 15
  • 24
1

There exists an opposite function called htmlspecialchars_decode() that you can use to convert back to normal text. You can find documentation on it in the PHP Manual.

Sean
  • 126
  • 1
  • 7
1

Use the html_entity_decode() function.

It decodes ALL html entities.

DO NOT USE htmlspecialchars_decode()!!! It won't work for things like A.

Try this:

echo htmlspecialchars_decode('A'), html_entity_decode('A');

It should output AA.

Documentation

potashin
  • 44,205
  • 11
  • 83
  • 107
Ismael Miguel
  • 4,185
  • 1
  • 31
  • 42
  • @user2721465 You are welcome. Notice that to use this function, you will find that using `htmlentities()` is more useful, instead of `htmlspecialchars()`. – Ismael Miguel Oct 10 '14 at 17:45
  • The asker explicitly specified that he wants to perform the inverse of a `htmlspecialchars` call, rather than having to decode arbitrary HTML entities like `A`. Given that condition, the warning against using `htmlspecialchars_decode()` seems wrong - it will work fine for the OP's use case. – Mark Amery Oct 12 '14 at 19:59