[TYPO3-german] Umlaut-Problem in PHP 5.3.3

Andreas Becker ab.becker at web.de
Tue Mar 1 15:08:46 CET 2011


Checke einfach noch einmal:

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients

[client]
default-character-set = utf8
...

[mysqld]
# setting db server to UTF8
collation_server=utf8_general_ci
character_set_server=utf8

# On the other hand, if you want to ensure MySQL always stores
# and retrieves data in the UTF-8 charset regardless of what a
# client requests add the following directive to the [mysqld] section
# of your MySQL config file.

#skip-character-set-client-handshake


# * Basic Settings
...

[mysqldump]
...

[mysql]
# Setting MySql System to utf8
default-character-set=utf8

collation_connection=utf8_general_ci


#no-auto-rehash # faster start of mysql but no tab completition

[isamchk]
...

-----------------------------

In localconf.php deactiviere/loesche die settings die man noch zuvor
gebraucht hatte:
(TIP: teste zuerst mit deactivieren)

// UTF8
//$TYPO3_CONF_VARS['BE']['forceCharset'] = 'utf-8'; // loeschen
//$TYPO3_CONF_VARS['SYS']['setDBinit'] = 'SET NAMES utf8'; // loeschen
$TYPO3_CONF_VARS['SYS']['t3lib_cs_convMethod'] = 'mbstring';
$TYPO3_CONF_VARS['SYS']['t3lib_cs_utils'] = 'mbstring';
//$TYPO3_CONF_VARS['SYS']['UTF8filesystem'] = '1'; // loeschen

-----------------------------

in php.ini

If your scripts will contain multi-byte characters be sure to encode them in
UTF-8. Any decent text editor can do this for you (I like notepad++). In
your PHP config, set the default_charset and mbstring.internal_encoding to
UTF-8.

; PHP's default character set is set to empty.
; http://php.net/default-charset
;default_charset = "iso-8859-1"
default_charset = "UTF-8"
mbstring.internal_encoding = UTF-8

-----------------------------

Apache

Web browsers need to know what character set to use for the documents you
send it. Your server needs to include charset=utf-8 in the Content-Type HTTP
header so clients will handle UTF-8 encoded documents correctly. There are a
variety of ways you can do this and a simple approach would be to set UTF-8
as the default character set. Here are a few ways you can do this -- add the
method of your choice to httpd.conf or your root htaccess file:


// make utf-8 the default charset for everything
AddDefaultCharset UTF-8

// or specifically for php, html, xml, javascript etc..
AddCharset UTF-8 .php
AddCharset UTF-8 .html
AddCharset UTF-8 .xml
AddCharset UTF-8 .js

-----------------------

TESTING

An example in code. From Sam Ruby’s i18n Survival Guide, he recommends using
the string Iñtërnâtiônàlizætiøn for testing. Counted with your eye, you can
see it contains 20 characters;

Iñtërnâtiônàlizætiøn
12345678901234567890

But counted with PHP‘s strlen function...

<?php
echo strlen('Iñtërnâtiônàlizætiøn');
?>

PHP will report 27 characters. That’s because the string, encoded as UTF-8,
contains multi-byte characters which PHP‘s strlen function will count as
being multiple characters.

Life gets even more interesting if you run the following2);

<?php
header('Content-Type: text/plain; charset=ISO-8859-1');

$str = 'Iñtërnâtiônàlizætiøn';

$out = '';
$pos = '';
for($i = 0, $j = 1; $i < strlen($str); $i++, $j++) {
$out .= $str[$i];
if ( $j == 10 ) $j = 0;
$pos .= $j;
}

echo $out."\n".$pos;
?>

You should see something like;

Iñtërnâtiônà lizætiøn
123456789012345678901234567

>>>>
http://www.phpwact.org/php/i18n/charsets
http://www.itnewb.com/v/UTF-8-Enabled-Apache-MySQL-PHP-Markup-and-
http://www.joelonsoftware.com/articles/Unicode.html
http://en.wikipedia.org/wiki/Category:Character_sets
http://en.wikipedia.org/wiki/Character_encoding
http://en.wikipedia.org/wiki/UTF8
>>>>


=================================

Locales

root at srv:/# locale -a
C
da_DK.utf8
de_AT.utf8
de_BE.utf8
de_CH.utf8
de_DE.utf8
de_LI.utf8
de_LU.utf8
en_AU.utf8
en_CA.utf8
en_GB.utf8
en_US.utf8
es_ES.utf8
fi_FI.utf8
fr_FR.utf8
it_IT.utf8
ja_JP.utf8
nl_NL.utf8
nn_NO.utf8
POSIX
ru_RU.utf8
sv_SE.utf8
th_TH.utf8
zh_CN.utf8
zh_HK.utf8



root at srv:/# locale
LANG=en_GB.UTF-8
LC_CTYPE="en_GB.UTF-8"
LC_NUMERIC="en_GB.UTF-8"
LC_TIME="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
LC_MONETARY="en_GB.UTF-8"
LC_MESSAGES="en_GB.UTF-8"
LC_PAPER="en_GB.UTF-8"
LC_NAME="en_GB.UTF-8"
LC_ADDRESS="en_GB.UTF-8"
LC_TELEPHONE="en_GB.UTF-8"
LC_MEASUREMENT="en_GB.UTF-8"
LC_IDENTIFICATION="en_GB.UTF-8"
LC_ALL=
loc

The Easy Way

Install debconf (i.e. run apt-get update then apt-get install debconf, as
root)
Run dpkg-reconfigure locales as root
The Hard Way

Edit /etc/locale.gen as root. If /etc/locale.gen does not exist, create it.
An example /etc/locale.gen is below.
Run /usr/sbin/locale-gen as root
A sample /etc/locale.gen

# This file lists locales that you wish to have built. You can find a list
# of valid supported locales at /usr/share/i18n/SUPPORTED. Other
# combinations are possible, but may not be well tested. If you change
# this file, you need to rerun locale-gen.
#
# XXX GENERATED XXX
#
# NOTE!!! If you change this file by hand, and want to continue
# maintaining manually, remove the above line. Otherwise, use the command
# "dpkg-reconfigure locales" to manipulate this file. You can manually
# change this file without affecting the use of debconf, however, since it
# does read in your changes.

en_US.UTF-8 UTF-8

2011/3/1 Sven Kalbhenn <sven at skom.de>

> Hallo zusammen,
>
> ich habe mir einen neuen Server gegönnt und versuche gerade eine
> TYPO3-Installation (Version 4.5.2) auf den neuen Server umzuziehen.
> Leider werden auf dem neuen Server jetzt die Umlaute sowohl im Backend als
> auch im Frontend immer falsch angezeigt (z.B. ä statt ä), obwohl auf
> beiden Servern UTF-8 zum Einsatz kommt.
>
> Auf dem alten Server lief:
> - PHP 5.2.6
> - MySQL 5.0.51a
>
> Auf dem neuen Server läuft:
> - PHP 5.3.3
> - MySQL 5.1.46
>
> Ich habe mit  "mysqldump --default-character-set=utf8 myDB > myDB.sql"
> einen Datenbank-Dump erstellt.
> Diesen Dump habe ich dann auf dem neuen Server mit  "mysql -D
> --default-character-set=utf-8  myDB < myDB.sql" wieder eingespielt.
> (In beiden Fällen habe ich es auch ohne --default-character-set=utf-8
> versucht - ohne dass sich was geändert hat.)
> Unter PhpMyAdmin sehen auch beide Datenbanken und auch die Einträge gleich
> aus.
> In beiden TYPO3-Installationen habe ich "forceCharset" auf "utf-8" gesetzt.
>
> Trotzdem werden die Umlaute auf dem neuen Server falsch angezeigt. :-(
> Ich habe bereits mehrere Stunden lang, alle möglichen Varianten ausprobiert
> - ohne Erfolg.
> Jetzt bin ich mit meinem Latein am Ende! :-((
>
> Hat irgend jemand eine Idee was ich falsch mache???
> Für jeden Tipp wäre ich sehr dankbar!!
>
> Viele Grüße…Sven
>
> _______________________________________________
> TYPO3-german mailing list
> TYPO3-german at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-german
>


More information about the TYPO3-german mailing list