1

Whenever I use certain unique characters such as ™ the page outputs this symbol:

question mark

How can I convert these characters so that they can be displayed normally on the page?

I'm currently using this PHP, but it removes the characters instead of converting them into characters that can be displayed normally:

function convert_to($str, $target_encoding = "UTF-8") {
    $encoding = mb_detect_encoding($str, "auto");
    $target = str_replace("?", "[question_mark]", $str);
    $target = mb_convert_encoding( $target, $target_encoding, $encoding);
    $target = str_replace("?", "", $target);
    $target = str_replace("[question_mark]", "?", $target);
    return $target;
}
mightyspaj3
  • 471
  • 1
  • 8
  • 22

2 Answers2

2

That "question mark character" is actually an unreadable UTF-8 character. You'll need to change the original ™ character to ™ or adjust the encoding options for your PHP server. Here is another post that discusses a similar issue: Convert any string to UTF-8

Community
  • 1
  • 1
SteveK
  • 995
  • 5
  • 17
1
echo htmlentities($str, ENT_QUOTES, 'UTF-8');

Use htmlentities

Ghostman
  • 6,042
  • 9
  • 34
  • 53