aron n
aron n

Reputation: 597

How do I parse foreign languages and store in MySQL?

Hi when I parsing web using PHP the other language sites like chinese japanese etc.. I am getting wired characters. so How can I preserve its original form while storing it in MySQL??

technologies which I have used is

dom document

json_decode

Upvotes: 0

Views: 2223

Answers (1)

Michael Low
Michael Low

Reputation: 24506

MySQL can store data in Unicode. If you set the MySQL database, table and column encodings to UTF-8 you can store the foreign language in there correctly. You should send a 'SET NAMES utf8' command to MySQL when connecting to it via PHP each time too, to make sure it knows you're sending data in UTF-8.

A bigger problem is with PHP, which still has no real Unicode support. That seems kind of unbelievable for a major web development language in 2011 to me, but there you go. It'll work OK if all you do in PHP is get/update/display the Unicode data from MySQL, but you'll run into problems if you try do much string manipulation with it.

Data sent via ajax (e.g. your JSON data) also has to be sent UTF-8 encoded, so you need a <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> on each of your HTML pages too.

Upvotes: 1

Related Questions