I have a database table and two columns are being saved differently.
Table
id title description
-----------------------------------------------------------
1 Test - ñ <p>ñå</p>
As you could see the title was being saved as is and no encoding is being done. The description however is saved as an encoded string (it stands for <p>ñå</p>
).
I'm having a bit of trouble displaying them correctly on a page.
Here are my approaches so far:
Title
echo $data['title'];
- doesn't work and displays asTest - ñ
.echo html_entity_decode($data['title'], ENT_QUOTES, "UTF-8");
- still doesn't work and displays asTest - ñ
.echo html_entity_decode($data['title'], ENT_XML1, "UTF-8");
- still doesn't work and displays asTest - ñ
.
Description
echo $data['description'];
- just shows<p>ñå</p>
.echo html_entity_decode($data['description'], ENT_QUOTES, "UTF-8");
- doesn't work and just displaysTest - ñ
.echo html_entity_decode($data['description'], ENT_XML1, "UTF-8");
- THIS SEEMS TO WORK although I'm not sure why settingENT_XML1
fixes the problem with the description but not on the title.
Anyways, I'm not really knowledgeable about character encoding and HTML entities and special characters. Could you help me solve this problem so that both the title and description displays well. I'm not sure I'm doing the proper steps here but I was just trying different combinations of solutions.
ñå
`. – deceze Jun 21 '16 at 15:29