`

Typo3 乱码问题

阅读更多
UTF8 and TYPO3

To have a real utf8 TYPO3 Installation may be a difficult thing. "Real" in that case means that everything is UTF8: TYPO3 and Database!

To have a working utf8 Database may be difficult, and is not possible in any case (e.g. if you dont have permissions to configure the database.)

Additionaly you have to pay attention if you want to migrate an existing TYPO3 Installation to UTF8, which may be very difficult if you allready have diffrent charsets in your database.

This article would like to provide a deep overview over this subject.

What is charset and UTF8?
Ok just a small information on that topic: Every char is represented just with Bit's and Bytes (=8Bit) in your computer. Every application needs to know the mapping beetween this bitcodes and the characters (=the characterset). Therefore exits diffrent standards like the well known ASCII for example. Most charsets uses one byte for each char, but with such one-byte-charsets it is only possible to code 255 diffrent chars --> this is the reason why there are so many diffrent charsets, because every language may need its own set of chars. The problem gets even bigger if you think of all the chinese and cyrillic languages.

Therefore the Unicode standards were born, in its original intention 3bytes are used to code a char. To be more compatible to other charsets UTF8 was defined: In UTF8 a char could be encoded with one, two or three bytes! The trick is simple: if the first bit of a byte is '0' it means it is a one-byte-char: So it was possible to encode the first 128 chars similar to the well known ISO (or ASCII) charsets.

An example:

'ä' is encoded in ASCII with this bits 11100100 (=228)
it is encoded in UTF8 with this bits: 11000011 10100100 (195 and 164)
This means if you interpret this UTF8 char as ASCII, you will get two chars "ä".

Got it?

Collations
Is a set of rules for comparing characters. So a DBMS can sort and compare stringvalues. ( a

TYPO3 Settings
To set UTF8 support in TYPO3 is simple: Just go to the Installtool and set the option forceCharset to "utf-8"

Mysql Settings
This is the difficult part. MYSQL DBMS has 6 diffrent settings for charactersets.

You can see the actual settings by executing the query:

show variables;
-----
character_set_client            | latin1                          
| character_set_connection        | latin1
| character_set_database          | utf8
| character_set_results           | latin1
| character_set_server            | utf8
| character_set_system            | utf8
| character_sets_dir              | /usr/share/mysql-500/charsets/


Read more: http://dev.mysql.com/doc/refman/5.0/en/charset.html

A.) Configure the mysql charactersets
This needs special rights on the server, you find informations in the mysql-reference. Normaly this has to be done:

Check mysqlserver settings (recompile or start with parameter "--character-set-server" to force utf8)

Check mysqlclient settings: Edit my.cnf and be sure that there is a line like:

[client]
default-character-set=uft8

B.) Force Charset by changing class.t3lib_db.php
Often it is easier to force the charset by executing the query:

SET CHARACTER SET utf8;

So it is neccessary to modify the TYPO3 databaseclass "class.t3lib_db.php" and insert the line:

$this->admin_query('SET CHARACTER SET utf8');

You have to insert this after the mysql_pconnect() round line 897.

It is also possible to use the SQL "SET NAMES utf8", which in addition to the SQL above also sets characterset of the connection. (This may cause problems in some environments). Read more:
http://dev.mysql.com/doc/refman/5.1/de/charset-connection.html
http://dev.mysql.com/doc/refman/5.1/en/charset-connection.html

C.) Force Charset with setDBinit configuration (>TYPO3 4.0)
Since TYPO3 4.0 it is mot necessary to patch the class.t3lib_db.php. You can use the configurationoption "setDBinit":



(Thanks "pavel" for the tip)

Change Charset in an existing project
Open a lhell on your TYPO3 server
Make database-backup using mysqldump:
mysqldump -u user -p database > backupfile.sql
Drop the extisting database
Create new database
Be sure this new empty database is utf8. E.g. execute:
ALTER DATABASE databasename DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
Set TYPO3 force_charset Option (see above)
Modify the backupfile if required! (*1)
Change charset to utf8, for example by using the external tool recode:
RECODE latin1...utf8 backupfile.sql
Change all the "crate table" statements in this dumpfile. You have to replace "CHARSET=latin1" with "CHARSET=utf8". This can be done by using the commandline-tool sed:
sed 's/CHARSET=latin1/CHARSET=utf8/' backupfile.sql > backupfile_utf8.sql
Insert the changed databasedump:
mysql -u user -p database < backupfile_utf8.sql
There may be some problems with TemplaVoila mapping or with special chars in some plugins. Normaly this could be solved by recoding the relevant templatefiles.

(*1) Note from ries van Twisk:
"What I wanted to mention is you don't have to recode
a MySQL dump since resent versions of MySQL dump
already dumps in utf-8."

Testing
Go to the backend. First check which charset is selected by the browser, it should be "UNICODE (utf-8)".

Then create a new page with special chars e.g. "ähm übung" and save it.
Go to the Tool "phpmyadmin" and search this record in the table "pages", if you see exactly the same title everthing works fine! (If not go to Mysql settings again :-))
  • 大小: 7.9 KB
分享到:
评论

相关推荐

    typo3中文 教程

    ### Typo3中文教程:创建一个基本扩展件 #### 一、引言 Typo3是一款功能强大的开源内容管理系统(Content Management System, CMS),被广泛应用于搭建各种类型的网站。本教程旨在帮助初学者了解如何在Typo3环境中...

    TYPO3简体中文语言包

    TYPO3是一款强大的开源内容管理系统(CMS),主要用于构建和管理网站。这款系统以其高度可扩展性和灵活性著称,能够满足各种复杂的企业级需求。"TYPO3简体中文语言包"是针对该系统的本地化组件,目的是为了让中国...

    typo3 入门教程

    ### Typo3 入门教程知识点详解 #### 引言 **教程的目标:** 本教程旨在帮助初学者熟悉Typo3的基本操作与功能。通过实际案例——为虚拟足球俱乐部“FCBigfeet”构建网站的过程,学员将掌握一系列核心技能。学完本...

    typo3开源代码,可以直接用

    - **官方文档**:Typo3 提供详尽的官方文档,涵盖了从安装到高级开发的各个阶段,是学习和解决问题的重要参考。 - **社区支持**: Typo3 社区活跃,开发者可以在论坛上提问并获得帮助。 - **GitHub 仓库**:开源...

    typo3插件

    **TYPO3是一个强大的开源内容管理系统(CMS),它以其高度可扩展性和灵活性著称。在TYPO3的世界里,插件是增强...如果你在使用过程中遇到问题或想进一步交流,不要犹豫,分享你的经验,你会发现TYPO3社区的友好和支持。

    TYPO3 6.0 中文版(带模板,安装即可用)

    TYPO3是一款开源的内容管理系统(CMS),它以强大的可扩展性和高度的定制性著称,尤其适合大型企业级网站的构建。这里的"TYPO3 6.0 中文版(带模板,安装即可用)"是一个特别为中文用户定制的版本,包含预设的模板,...

    TYPO3 中文版 v7.6 LTS

    TYPO3是一个企业级的开源内容管理系统,可以用来建设和管理各种类型的网站,从小站点、非盈利组织到针对大型企业的多语言企业级解决方案。极益平台1.0版本将基于TYPO3 7.3.1。系统包括前台、业务后台、总后台三个...

    TYPO3中的多语系网站.doc

    TYPO3是一款强大的开源内容管理系统(CMS),用于构建和管理网站。在TYPO3中,实现多语系网站有两种主要方法:1) "Two-Tree" 概念和2) "one-tree-fits-all-languages" 概念。这两种方法各有优缺点,适用于不同的需求...

    Typo3 内容管理系统 v6.2.2.zip

    TYPO3 6.2.2 更新说明: 修复了一个重要的 bug, 修复了 6.2.1 的一些回退问题, 建议 6.2.1 和 6.2.0 的用户尽快升级。   TYPO3是一个企业级的开源内容管理系统,可以用来建设和管理各种类型的网站,从小站点...

    TYPO3 中文版 v7.3.1.zip

    TYPO3是一个企业级的开源内容管理系统,可以用来建设和管理各种类型的网站,从小站点、非盈利组织到针对大型企业的多语言企业级解决方案。 极益平台1.0版本将基于TYPO3 7.3.1。系统包括前台、业务后台、总后台三个...

    typo3_CMS_v9.5.0

    Typo3内容管理系统,是基于PHP4/PHP5+MYsql的内容管理系统(框架)(CMS/CMF),兼容PHP4和PHP5.数据库系统除Mysql之外,也能运行于Oracle, MS-SQL, ODBC, LDAP 等其它数据库系统,支持Typo3的服务器系统:Apache或者IIS...

    typo3cms V7.6.18建站源码

    Typo3内容管理系统,是基于PHP4/PHP5+MYsql的内容管理系统(框架)(CMS/CMF),兼容PHP4和PHP5.数据库系统除Mysql之外,也能运行于Oracle, MS-SQL, ODBC, LDAP 等其它数据库系统,支持Typo3的服务器系统:Apache或者IIS...

    Typo3 Enterprise Content Management

    5. **安全性**:作为企业级CMS,Typo3 非常重视安全问题。它提供了多种安全措施,如权限控制、数据加密等,确保网站的安全性和稳定性。 #### 三、安装与配置 1. **环境准备**:在安装 Typo3 之前,需要准备好合适...

    [CMS程序]Typo3 4.2.5_typo3_src-4.2.5.zip

    尽管4.2.5是较早的版本,但Typo3社区持续关注安全问题,并发布了多个安全补丁。为了保护网站免受潜在威胁,建议及时更新到最新稳定版本,同时定期检查并应用安全更新。 【总结】 Typo3 4.2.5是一个功能强大的CMS...

    TYPO3 Extension Development

    ### TYPO3扩展开发知识点概述 #### 一、TYPO3简介 TYPO3是一款广泛使用的开源内容管理系统(CMS),它为创建和管理网站提供了强大的工具。TYPO3不仅适用于小型项目,还能支持复杂的多语言企业级网站。其灵活性和可...

    Typo3 v4.5.18 LTS.zip

    Typo3是开源内容管理系统(CMS)和内容管理框架(CMF)的领导性品牌之一,和CMSware一样是一个真正的高端企业级的产品;由于其不是面向低端用户的产品,因而在国内影响相当有限。 Typo3主要是面向中高级php水平的开发者...

    此 TYPO3 扩展提供 ViewHelpers 和配置,以根据 TYPO3 的图像裁剪工具呈现有效的响应式图像

    6. **兼容性**:确保此扩展与当前版本的 TYPO3 兼容至关重要,因为TYPO3 经常更新以引入新特性和修复问题。开发者应检查扩展的版本信息,确保其与网站上运行的 TYPO3 版本匹配。 总之,"sms-responsive-images" ...

    [CMS程序]Typo3 dummy 4.26 (集成后台简体中文语言包)(PHP5+)_typo3-all.zip

    **Typo3 CMS系统介绍** Typo3是一款开源的内容管理系统(CMS),专为构建复杂的、企业级的网站而设计。它的灵活性和可扩展性使其在众多CMS中脱颖而出,尤其适合大型组织和机构使用。该系统提供了强大的内容编辑、...

    TYPO3.CMS:TYPO3核心-企业内容管理系统。 http:git.typo3.orgPackagesTYPO3.CMS.git的同步只读镜像

    TYPO3 CMS TYPO3是在GNU GPL下发布的基于PHP的开源Web内容管理系统。 TYPO3是Kasper Skaarhoj版权所有(c)1999-2020。 本文档提供了TYPO3的基本介绍。 入门 TYPO3需要具有PHP的Web服务器和数据库(例如MySQL)。 ...

Global site tag (gtag.js) - Google Analytics