Shishant
Shishant

Reputation: 9294

SQLite Charset / Character Encoding change in php

I have some fancy characters (medical symbols) in sqlite database, for eg: Aβ2M but when I fetch records using Codeigniter SQLite PDO Driver the output result is Aβ2M.

I read this article How to change character encoding of a PDO/SQLite connection in PHP? and tried utf_decode which results in this output A?2M

So how and what encoding should I set while fetching records to fix this issue?

Upvotes: 2

Views: 3325

Answers (1)

John Flatness
John Flatness

Reputation: 33769

If the data is truly stored as UTF-8 in your database, declaring that charset (either on the page with a meta tag or an HTTP header) should be enough.

As long as you're just displaying the text, it's not particularly important that PHP "understands" what the characters actually are, but the browser does need to know the proper charset to interpret and correctly display the page. (Of course, if you start doing any processing on your strings in PHP, you'd need to make sure that you're using multibyte-aware functions and providing the correct charset there also).

utf8_decode won't help you here, since you're trying to show characters that aren't part of ISO 8859-1, the character set that function decodes to.

Upvotes: 2

Related Questions