0

I would like to decode htmlspecial charater for example ' to be transfomed as '

I would like to avoid making regexp.

I tried htmlspecialchars_decode($mystring); It works for charater such as à but not for one with character code.

pernifloss
  • 446
  • 9

1 Answers1

0

Use html_entity_decode() https://www.php.net/manual/en/function.html-entity-decode

<?php

echo html_entity_decode('&#39;');

// outputs '

Try it here https://3v4l.org/IcDlB

delboy1978uk
  • 12,118
  • 2
  • 21
  • 39
  • htmlspecialchars_decode works fine too (at least for this specific character code), if you have a new enough version of PHP: https://3v4l.org/10dDv – ADyson Jul 27 '23 at 12:28
  • I first thought so as well, then seeing that https://stackoverflow.com/a/9587822/367456 suggested it already and found out that for both htmlspecialchars_decode() and html_entity_decode() it is not always the case for all numeric entities. Updated the answer then. E.g. on my local box with PHP 8.2 for **both** it does not translate '. – hakre Jul 27 '23 at 12:29
  • I already use `htmlspecialchars_decode(html_entity_decode($mystring));` , `'` are still present. As my title specify I use PHP 7.4 – pernifloss Jul 27 '23 at 12:47