phputf-8character-encodingmojibake

Getting ’ instead of an apostrophe(') in PHP


I've tried converting the text to or from utf8, which didn't seem to help.

I'm getting:

"It’s Getting the Best of Me"

It should be:

"It’s Getting the Best of Me"

I'm getting this data from this url.


Solution

  • To convert to HTML entities:

    <?php
      echo mb_convert_encoding(
        file_get_contents('http://www.tvrage.com/quickinfo.php?show=Surviver&ep=20x02&exact=0'),
        "HTML-ENTITIES",
        "UTF-8"
      );
    ?>
    

    See docs for mb_convert_encoding for more encoding options.