0

Apologies upfront if this has been asked before but it's not an easy question to search for.

I have MySQL database record with ’ in the string, eg the "main reasons for the economy’s outperformance"

So I retrieve the string in PHP and convert it:

$text = mb_convert_encoding($text, "HTML-ENTITIES", "UTF-8");

Now I have "main reasons for the economy’s outperformance"

So next I try to decode the html:

$text = html_entity_decode($text), ENT_QUOTES, "UTF-8");

And now I'm back to strange characters again, "main reasons for the economy’s outperformance"

So my question is how do I get rid of the characters and deal with text as a human reads it, then (after adding slashes) replace the record in the database? I'd rather not have to replace every strange character or html entity individually in MySQL, but it looks like that's the only thing I know how to do that works.

Thanks for pointers.

WCWC
  • 15
  • 1
  • 6
  • Actually it should read: Now I have "main reasons for the economy& rsquo; s outperformance" (without the space) – WCWC Jul 07 '17 at 16:52
  • do you have `` in the head of your html ? – Casimir et Hippolyte Jul 07 '17 at 16:56
  • The original source that the text came from has . But I am not trying to display it, I just want to fix the text in the database so I get actual quotes, not html entities or weird characters. – WCWC Jul 07 '17 at 16:59
  • I think the problem is your database encoding. Is it UTF-8? If yes, then your problem is that the strings were in ISO-8859-1 when you stored them. Or you tried to store UTF-8 strings in an ISO-8859-1 table... Either way, I think you are looking for http://php.net/manual/en/function.iconv.php Or maybe just changing the DB encoding might do the trick. – masterfloda Jul 07 '17 at 19:07
  • masterfloda--that sounds logical. The database is UTF-8, I assumed the strings being imported into it in the first place were also since that's what the meta charset says. Could there be a PHP setting on the host's server that is getting in the way too? – WCWC Jul 07 '17 at 19:58
  • See Mojibake in http://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored – Rick James Jul 09 '17 at 04:25

0 Answers0