Page 1 of 1
Please help me with these strings
Posted: Mon Apr 07, 2008 5:28 pm
by devdept
Hi All,
I am getting crazy behind these two damn string

:
Code: Select all
TEZ YAPI ?N?AAT TAAH. MÜH. B?LG. T?C. VE
+44 (0588) 555 6666
The first is a real turkish company name, the second a trivial phone number.
I can't, again I can't, find a reliable way to store them in a mySQL database and restore them correctly because of the international chars and the plus sign.
I would love to see a very easy (working

) example using PHP / Sessions / mySQL composed by form.php, process.php and display.php files and a test mySQL table.
Very grateful to you all,
Alberto
Re: Please help me with these strings
Posted: Fri Apr 18, 2008 12:01 pm
by samb0057
When you create your MySQL tables, did you use the "utf8_general_ci" collation?
Re: Please help me with these strings
Posted: Sat Apr 19, 2008 4:00 am
by devdept
No, how should I do?
Thanks,
Alberto
Re: Please help me with these strings
Posted: Sat Apr 19, 2008 4:46 am
by onion2k
samb0057 wrote:When you create your MySQL tables, did you use the "utf8_general_ci" collation?
The collation makes no difference to the way the data is stored, just the way it's sorted when you fetch results. The important thing is the table charset, and getting the MySQL client, PHP and the HTML all to use the same encoding.
When you create your database table you need to include the CHARSET directive.. eg
Code: Select all
CREATE TABLE IF NOT EXISTS `advert` (
`advert_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`title` varchar(255) collate utf8_unicode_ci NOT NULL DEFAULT '',
`publish_date` date NOT NULL DEFAULT '0000-00-00',
`publish` tinyint(3) UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`advert_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;
That will make MySQL store the data as UTF8 if you send it UTF8 data rather than converting it to something else.
You'll also need to put PHP's MySQL client into UTF8 mode using..
It's best to do that immediately you connect to the database.
And finally you need to make sure the page is displayed as UTF8 too... Personally I do that with a header().
Code: Select all
header("Content-Type: text/html; charset=utf-8");
There are probably easier ways to do it, but that's what works for me.
Re: Please help me with these strings
Posted: Sat Apr 19, 2008 7:48 am
by devdept
So any app dealing with international chars does what you explained to aviod troubles?
Where can I find more info about UTF8, what exactly does?
Thanks so much again,
Alberto
Re: Please help me with these strings
Posted: Sat Apr 19, 2008 8:15 am
by onion2k
devdept wrote:So any app dealing with international chars does what you explained to aviod troubles?
Honestly, I have no idea. That's the solution I developed for my sites. Other sites might do the same, they might not. I've never bothered looking.
devdept wrote:Where can I find more info about UTF8, what exactly does?
Google is a good place to start.
Re: Please help me with these strings
Posted: Mon Apr 21, 2008 2:53 am
by devdept
I found the following page.
http://en.wikipedia.org/wiki/Utf8
Thanks a lot again.
Alberto