0

i am facing some weird problem. I have following string stored in my mysql table :

The horses had been brought in from the hills and were tethered next to a pile of drying dung. All around were snowcapped peaks and on one side lay a shimmering lake of glacial blue water. The Kyrgyz men were deciding who would ride which horse. Kanybek looked at me, the only man left in our riding party, which had somehow slimmed down from 10 to three at the sight of the stallions. I'd heard about Kanybek, the best ulak player in the area (that’s polo played with a dead headless goat, the same as the Afghan bushkazi).

Kanybek was a man who could pluck a 10 som note from the ground at a full gallop, a man who could mount a steed with a back somersault. He had been born in the shadow of a horse, ridden before he could walk and drunk mare’s milk ever since. I had serious doubts whether Kanybek could begin to comprehend how crap I was at riding horses.

“This one is for you,” he said, his weathered face splitting into a champion grin. “It is the fastest.”

when i am retrieving it from db to php it starts showing instead . Following what i can see after retrieving it in php.

The horses had been brought in from the hills and were tethered next to a pile of drying dung. All around were snowcapped peaks and on one side lay a shimmering lake of glacial blue water. The Kyrgyz men were deciding who would ride which horse. Kanybek looked at me, the only man left in our riding party, which had somehow slimmed down from 10 to three at the sight of the stallions. I'd heard about Kanybek, the best ulak player in the area (that�s polo played with a dead headless goat, the same as the Afghan bushkazi).

Kanybek was a man who could pluck a 10 som note from the ground at a full gallop, a man who could mount a steed with a back somersault. He had been born in the shadow of a horse, ridden before he could walk and drunk mare�s milk ever since. I had serious doubts whether Kanybek could begin to comprehend how crap I was at riding horses.

�This one is for you,� he said, his weathered face splitting into a champion grin. �It is the fastest.�

i have tried many php functions with many combination but at last i didn't get anything.

mb_convert_encoding(), iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $description), htmlentities etc..

these all are returning empty string.

i have set

   <meta charset="utf-8">

i am using PDO to retrieve data and my database collections is utf-8.

Basically i am reading third party rss feed and via cron i am storing them in to my database.

Would appreciate your help.

Kalpit
  • 4,906
  • 4
  • 25
  • 43
  • what's your db encoding and what's your html page encoding? how do you connect to mysql? are you using `SET NAMES utf8`? – Peter Apr 10 '15 at 11:15
  • 1
    [Handling Unicode Front To Back In A Web App](http://kunststube.net/frontback/) – deceze Apr 10 '15 at 11:25
  • @deceze interesting thing is if i store above string in php variable and then if i am trying to decode its working fine but from db its not – Kalpit Apr 10 '15 at 11:58
  • I vote for reopening because the "UTF-8 all the way through" is too broad an answer -- the OP rarely knows where he failed to use utf8, and needs help locating it. – Rick James Apr 10 '15 at 15:54
  • @Kalpit - Please provide `SELECT col, HEX(col) ...` so we can see what was stored in the table. That will help determine (1) whether the problem is on input or output, and (2) what 'bad' encoding was used. I suspect it was MicroSquish's "smart quotes"; they don't work with latin1. – Rick James Apr 10 '15 at 15:57
  • Also please provide `SHOW CREATE TABLE`. – Rick James Apr 10 '15 at 15:57

1 Answers1

0

This is a pretty broad issue. You need to make sure that everything from form submissions, your PHP mysql/mysqli instance, and the database itself is set up to use UTF8 properly. See UTF-8 all the way through.

You probably need to add <meta charset="UTF-8"> to the <head> of your HTML document to let the web browser know that you're directly displaying UTF8 content. This will enable your web browser to show UTF8 content if it is able to.

If that doesn't help, try using utf8_decode().

Community
  • 1
  • 1
Frank
  • 664
  • 5
  • 15
  • 1
    Might it be possible to shed some light on why you downvoted this answer? – Frank Apr 10 '15 at 11:19
  • 1
    I upvoted because this is the right answer. – dotancohen Apr 10 '15 at 11:21
  • Please don't recommend `utf8_decode` as some sort of fallback. There's simply an encoding mismatch going on which should be solved by harmonising all the encodings, not by converting encodings manually to Latin-1. – deceze Apr 10 '15 at 11:24
  • We don't know what OP is doing since he's not provided much detail on this. It could be that the rest of his stack is fine. – Frank Apr 10 '15 at 11:29
  • @Frank i am not storing this data via form. i am reading rss feed of third party and i am storing them in to my db. i have set in my head. – Kalpit Apr 10 '15 at 11:42
  • @Kalpit You need to take care that you know what the encoding of that feed is and that you convert it to a defined encoding of your choice if necessary before storing it. – deceze Apr 10 '15 at 11:43
  • @deceze how can i do that? can you please guide me. – Kalpit Apr 10 '15 at 11:50
  • 2
    I downvoted it because there is no reason to use `utf8_decode` and it looks like OP has meta charset in . so I downvoted it because its not proper answer – Peter Apr 10 '15 at 11:51
  • 1
    @Kalpit Not in a comment. Open a new question in which you detail how you're fetching those feeds exactly. – deceze Apr 10 '15 at 11:51