-1
$html_str = "Random Text™ First Second Third";

echo $str = html_entity_decode($html_str);

outputs: Random Text™ First Second Third

now how do I convert $str to $html_str?

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Mo Huss
  • 11
  • 6
  • 1
    Note that you do not need to run `$html_str` through `html_entity_decode()` to output `Random Text™ First Second Third` - it will display just fine without any decoding. – junkfoodjunkie Aug 12 '17 at 19:23
  • @junkfoodjunkie you are absolutely right. Lets say, I want to save "Random Text™ First Second Third" in my mysql db like this:- "Random Text™ First Second Third". How would I do that? – Mo Huss Aug 12 '17 at 19:29
  • Well... i tested now, and the closest I got was using `htmlentities(string goes here)`- however, it stores the character as `™`, not `™`, which might be a problem, or not, depending. – junkfoodjunkie Aug 12 '17 at 20:44
  • @junkfoodjunkie that would be fine. When I try it, my db stores ™ as ⢠which is not even close. I am starting to think my mysql settings aren't right. I set the db coalition to utf8-bin btw. – Mo Huss Aug 12 '17 at 23:25
  • Everything needs to be UTF 8. The db, the files, etc. Also, I don't think utf8-bin is the right choice. On my cell phone right now, which limits things a bit, bit you might find some tips/answers here: https://stackoverflow.com/q/202205/1561164 – junkfoodjunkie Aug 12 '17 at 23:42

1 Answers1

1

Per the documentation: "html_entity_decode() is the opposite of htmlentities()..." http://php.net/manual/en/function.html-entity-decode.php

"htmlentities — Convert all applicable characters to HTML entities" http://php.net/manual/en/function.htmlentities.php

You want to use htmlentities

$html_str = htmlentities($str);

JHS
  • 1,423
  • 17
  • 29