character not displaying in UTF-8 in a html file

I have an html page, displaying some text content from the sql database. some of the characters were not displaying correctly in the html page, for example hyphens or dashes are displayed as question mark. I looked into the database and found that, that's how exactly data is in the database. this might be cause of the data entry using a different tool with encoding other than UTF-8.

any thoughts on how to resolve such encoding issue?
mikha eAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
most likely it's encoding issue. try read this:

HTML Encoding (Character Sets)
https://www.w3schools.com/html/html_charset.asp

remember to set the charset to "UTF-8".

you may also verify the data and how it was being pulled to ensure the data is in "correct" encoded format before populating to HTML
0
slightwv (䄆 Netminder) Commented:
What database product?

When dealing with possible character set issues in the database, you need to be careful how you confirm the data is bad.  The tool you use to verify the data might also have decoding issues and display it improperly when the data in the database is good.  I usually do a hex dump or similar function to verify what the stored data actually has.

>>any thoughts on how to resolve such encoding issue?

You definitely need to make sure the database can support the characters.  Then fix the data entry app to make sure it passes in the correct characters.  Depending on what was actually stored in the database, you have likely lost those characters.
0
lenamtlCommented:
Hi,

If the accentuated letter / special characters are ok in DB
Make sure you are saving the web page with correct encoding if your are using Notepad++ select Encoding -> Utf-8
some code editor (older version) require to select UTF-8 without BOM
If this is the case  I usually do is to add an accentuated letter in comment // é
 because some editor when re-editing the file won't save the correct encoding if there is no accentuated letter on the page code.

Make sure you have the correct meta on each page
<meta charset="UTF-8">

Open in new window


If the accentuated letter / special characters are not ok in DB
Make sure when saving to DB to set the character encoding.
here is my code example  (PHP PDO)
parent::__construct($DB_TYPE.':host='.$DB_HOST.';dbname='.$DB_NAME.';charset=utf8', $DB_USER, $DB_PASS);
 $this->exec('SET CHARACTER SET utf8');

Open in new window


In some case the browser / computer font may be the culprit, I use to have a font installed on my PC that break the display on some web site like Facebook, when I uninstall the problematic font everything was fine.
If the problem is only with one browser check the browser fonts parameters.
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.