0

I have tried solutions as specified in other questions but none have worked. The DB table column is set to utf8_general_ci. The problem is: one of the records contains a - (hyphen). When being echoed onto the page it's displaying as a question mark inside a diamond (�). I've tried to specify the content type in the header:

 header('Content-type: text/html; charset=utf-8');

However, it makes no difference - it's still not displaying the hyphen on the page. There is no encoding/decoding being done with the data prior to it being echoed so I'm confused as to what is causing this and how to fix this.

It's a client's site that I have taken over from a previous developer so I can't change any of the database encoding as it's a news outlet and I don't want to affect any indexed articles.

AmigoJack
  • 5,234
  • 1
  • 15
  • 31
ChrisYates
  • 31
  • 5

1 Answers1

0

For some reason other -s in the table were showing fine, yet the record in question I deleted the - and retyped - and saved and it now works fine... Odd.

AmigoJack
  • 5,234
  • 1
  • 15
  • 31
ChrisYates
  • 31
  • 5
  • No: you've deleted one character and inserted a different one - [there are different types of hyphens](https://en.wikipedia.org/wiki/Hyphen#Unicode) and they have their purposes. – AmigoJack Jan 18 '22 at 05:56
  • whats your solution ? – ChrisYates Jan 18 '22 at 13:58
  • To verify every point in [UTF-8 all the way through](https://stackoverflow.com/a/279279/4299358). Inspecting the raw bytes of your "record" (in MySQL/MariaDB it could be `SELECT hex( column )`) might also help, but needs knowledge of how text can be encoded. But since you modified it already you yet have to find a problematic dataset again. – AmigoJack Jan 18 '22 at 14:26
  • Would changing the column charset from utf8_general_ci to utf8_unicode_ci or another charset fix all the issues with records or would it be worth doing a dump of the data, converting the records and importing to a new db with the correct charset ? – ChrisYates Jan 18 '22 at 19:40
  • No. Simply don't! Wildly trying charsets is not a sane approach. So is wildly ex- and importing again. You can make an SQL dump of the whole DB (not just its data) and show it to someone who understands and has enough discipline to go through **all** the points: charset of DB, of the table, of the column, inspecting single datasets, inspecting how PHP accesses it, etc... – AmigoJack Jan 18 '22 at 21:47