Some rows in my database contain an apostrophe of sorts, that, when displayed with PHP, are converted to diamonds with a question mark in the center. Example, if it copies correctly: Captain Jim O’Brien
These “apostrophes” were inserted most likely via TinyMCE, where the user was copying and pasting from Word, or something from a Mac computer perhaps.
How can I display these “apostrophes”? When I view the row in PHPMyAdmin, the apostrophes are displayed (no diamond), so there is obviously a way.
My character encoding is set to UTF-8, and I’ve tried htmlspecialchars($string) and htmlentities($string), with no luck.
Characters are encoded in different places.
MySQL has a particular character encoding. By default, it is not UTF-8 but rather latin1.
The HTML document you generate using PHP also has a particular character encoding specified. Finally, the actual bytes in the HTML document factually assume a particular character encoding, which if you’re not careful can be different than the character encoding you specify for the document.
Verify that your MySQL encoding is set to UTF-8 as a first step. Note that MySQL can have the default character encoding for the database overridden on a per-table or even per-column basis.
You may be interested in this related post to get a deeper understanding of character encoding
Character Encoding and the ’ Issue
Update
Something put the data into the MySQL database in the first place. Perhaps that “something” was not using UTF-8 encoding.