phpencodingcharacter-encoding

How to decode &#39 in php


I am using an api that returns string that include encodings like this:

"It's a bit of a slow week"

I want this to be decoded into a human readable format using php.

I've tried html_entity_decode, rawurldecode, and quoted_printable_decode. I've even checked stackoverflow questions and tried more involved strategies including this one to no avail (it uses deprecated syntax anyway, and I wouldn't have liked keeping it in my application).

So does anyone know what type of encoding this is, and how to decode it in php?


Solution

  • html_entity_decode() ignores quotes by default, but will do what you want if you add the ENT_QUOTES flag:

    <?php
        $a = "It&#39;s working fine.";
        $b = html_entity_decode($a, ENT_QUOTES);
        var_dump($b); // string(18) "It's working fine." 
    ?>
    

    PHP Reference for html_entity_decode