Special chars & UTF-8: sometimes ok, sometimes wrong
am 18.10.2007 18:03:15 von tarmstrong
Hi.
Working with PHP 4.4 and mySQL 4.1, I've got some texts stored in a
UTF-8 table with special chars.
I serve a UTF-8 header within my HTML, Apache is configured to serve
UTF-8 and PHP scripts are saved in UTF-8 charset.
However, sometimes I get 'Espa=F1a' and other times 'Espa�a'. The
difference? I press F5 (Refresh) bottom on my web browser (I use
Firefox and Internet Explorer).
This is the first time I experience this issue.
When I have suffered problems with special chars I use utf8_decode or
utf8_encode, but I always try to store text data in UTF-8 charset and
serve them always with UTF-8 PHP scripts.
However, this is a very odd issue, since it happens only with text
taken from DataBase, but not from texts written in scripts :(
Any similar experience?
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: Special chars & UTF-8: sometimes ok, sometimes wrong
am 18.10.2007 19:09:40 von Instruct ICC
DQo+IEhpLg0KPg0KPiBXb3JraW5nIHdpdGggUEhQIDQuNCBhbmQgbXlTUUwg NC4xLCBJJ3ZlIGdv
dCBzb21lIHRleHRzIHN0b3JlZCBpbiBhDQo+IFVURi04IHRhYmxlIHdpdGgg c3BlY2lhbCBjaGFy
cy4NCj4NCj4gSSBzZXJ2ZSBhIFVURi04IGhlYWRlciB3aXRoaW4gbXkgSFRN TCwgQXBhY2hlIGlz
IGNvbmZpZ3VyZWQgdG8gc2VydmUNCj4gVVRGLTggYW5kIFBIUCBzY3JpcHRz IGFyZSBzYXZlZCBp
biBVVEYtOCBjaGFyc2V0Lg0KPg0KPiBIb3dldmVyLCBzb21ldGltZXMgSSBn ZXQgJ0VzcGHDsWEn
IGFuZCBvdGhlciB0aW1lcyAnRXNwYe+/vWEnLiBUaGUNCj4gZGlmZmVyZW5j ZT8gSSBwcmVzcyBG
NSAoUmVmcmVzaCkgYm90dG9tIG9uIG15IHdlYiBicm93c2VyIChJIHVzZQ0K PiBGaXJlZm94IGFu
ZCBJbnRlcm5ldCBFeHBsb3JlcikuDQo+DQo+IFRoaXM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aGUgdXRmOF91bmljb2RlX2NpIENvbGxhdGlvbiBjb2x1bW4s IGl0IGxvb2tzIGJh
ZC4NCg0KSE9XRVZFUiwgSSBhbSB1c2luZyBjaGFyYWN0ZXJzIGZyb20gdGhl IGV4dGVuZGVkIGFz
Y2lpIHRhYmxlIGh0dHA6Ly9hc2NpaXRhYmxlLmNvbS8NCg0KV2UgaGF2ZSBw ZW9wbGUgZnJvbSBk
aWZmZXJlbnQgY291bnRyaWVzIHVzaW5nIHRoZSBzYW1lIHNjcmlwdHMgYW5k IGRhdGFiYXNlLiAg
SSB0aG91Z2h0IHV0ZjhfdW5pY29kZV9jaSBzaG91bGQgaGFuZGxlIGFsbCBv ciBtb3N0LiAgV2hh
dCBzaG91bGQgSSBiZSB1c2luZz8NCkFsc28sIGluIHRoZSBodG1sIGZvcm0s IEkgaGF2ZSBtZXRo
b2Q9InBvc3QiIGVuY3R5cGU9Im11bHRpcGFydC9mb3JtLWRhdGEiLiAgSXMg dGhlcmUgYSBmb3Jt
IHByb3BlcnR5IG5lZWRlZCBhcyB3ZWxsPw0KX19fX19fX19fX19fX19fX19f X19fX19fX19fX19f
X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18NCkJvbyHCoFNj YXJlIGF3YXkgd29y
bXMsIHZpcnVzZXMgYW5kIHNvIG11Y2ggbW9yZSEgVHJ5IFdpbmRvd3MgTGl2 ZSBPbmVDYXJlIQ0K
aHR0cDovL29uZWNhcmUubGl2ZS5jb20vc3RhbmRhcmQvZW4tdXMvcHVyY2hh c2UvdHJpYWwuYXNw
eD9zX2NpZD13bF9ob3RtYWlsbmV3cw==
Re[2]: Special chars & UTF-8: sometimes ok, sometimes wrong
am 19.10.2007 08:15:09 von Vicente
>> I serve a UTF-8 header within my HTML, Apache is configured to ser=
ve
>> UTF-8 and PHP scripts are saved in UTF-8 charset.
>> However, this is a very odd issue, since it happens only with text
>> taken from DataBase, but not from texts written in scripts :(
>>
>> Any similar experience?
yes, it depends of the translation between tables and html pages.
I manage frequently standard configurations in Apache for Spanish
websites. On my view, it's better not changing the Apache
configuration. Instead that, be focused in having a latin_set=20
characters in your Mysql tables, in example latin1_swedish_ci.
As a guide, when I open phpMyAdmin, I have my tables with
latin1_swedish_ci in where appears España. Then, having the HTML
pages with
CONTENT=3D"text/html;charset=3Dutf-8"> it works without problems.
You can use use the PHP utf8_decode() function but it will be a hard
work for all variables in the whole site.
If you are now in a mess, I recommend you putting the Apache
configuration in the standard way. Restart, and load your HTML page,
changing the page codification using UTF and ISO-8859-1.
In this way, you can know what codification demands your HTML page to
show DB dates in a right way according the actual state of you tables.
If still you are not able to see the characters in any way, then you
can export and re-import your tables choosing a latin1_set and then
problem will be solved using UTF-8 in the HTML pages.
But if you change Apache configuration, it can interfere with other
previous scripts or tables, I don't recommend you.
It is my experience.
Hope it helps,
Vicente,
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php