Solved

Character encoding problems

Posted on 2009-04-15
5
334 Views
Last Modified: 2013-11-19
I'm working on a website that has a nasty problem. Some pages use UTF-8, other ISO-8859-1. Data is entered in the database using both methods. Now it turns out that for (at least) one of those pages the encoding is changed, resulting in data in the table that is UTF-8 for some records, and ISO-8859-1 for other. The database is set to 8859-1.

Is it possible to detect per record which encoding is used? Depending on the encoding I could use a php-function like utf8-encode.
0
Comment
Question by:R7AF
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 62

Expert Comment

by:gheist
ID: 24150509
What do you mean by pages - 4kB CPU pages/16kB database pages/Webpages
0
 
LVL 13

Author Comment

by:R7AF
ID: 24150765
I mean webpages.
0
 
LVL 62

Expert Comment

by:gheist
ID: 24150887
here is possibility for dual interpretation - from page headers and from Meta tags....
0
 
LVL 13

Author Comment

by:R7AF
ID: 24155203
The data is already entered in the database table. The data is a mix of ISO-8859-1 and UTF-8. When I publish the data on a html page (PHP generated), and set that page to either ISO-8859-1 or UTF-8 (using php page headers or html meta tags), some of those records don't have the correct encoding type. Because I don't know which records that are, I would like to be able to translate the text into another encoding when publishing that text. I would like to know whether it's possible to detect the encoding type based on a text string.
0
 
LVL 62

Accepted Solution

by:
gheist earned 500 total points
ID: 24155895
PHP iconv or mbstring can detect encodings to some extent.
You can try PostgreSQL's iconv functionality also to emit extra encoding field, or convert everything to UTF on output.
0

Featured Post

Webinar: Security & Encryption in the MySQL world

Join Percona’s Solutions Engineer, Dimitri Vanoverbeke as he presents “Security and Encryption in the MySQL world” on Thursday, July 6, 2017 at 7:00 am PDT / 10:00 am EDT (UTC-7).

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
This video teaches users how to migrate an existing Wordpress website to a new domain.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question