Stoppt die Vorratsdatenspeicherung! Jetzt klicken &handeln! Willst du auch an der Aktion teilnehmen? Hier findest du alle relevanten Infos und Materialien:

Archived entries for utf8

mbstring Functions by default

Mal wieder ein cooler Tip von dem ich nichts wusste. Wenn man mit UTF-8 arbeitet soll man ja in PHP die Stringfunktionen der mbstring Erweiterung nutzen. Statt sich durch den Quellcode zu wühlen und mail durch mb_send_mail, strtoupper durch mb_strtoupper usw usf zu ersetzen gibt es die Möglichkeit den Wert mbstring.func_overload in der php.ini zu verwenden.

You can set a value to mbstring.func_overload in php.ini. The value set for this function decides which functionality is overloaded by default with the mbstring variety:

  1. overloads the mail functions. So you don’t have to substitute mail with mb_send_mail in your code. The mail functuion it self will work like mb_send_mail if mbstring.func_overload is set to 1 in php.ini
  2. enables string functions overloading
  3. enables regular expression functions overloading
  4. enables mail, strings and regular expressions overloading

Mehrsprachige Webseiten mit PHP

Bei thinkphp gibt es eine gute Zusammenfassung der Basics auf die man bei der Entwicklung von Webseiten mit UTF-8 achten muss.

Unicode mit PHP

Scheinbar schon etwas älter, aber trotzdem sehr gut: Unicode for the working PHP programmer

Die Empfehlung:

  • Explicit use of UTF-8, marked with
    • “mb_language(‘uni’); mb_internal_encoding(‘UTF-8’);” at the top of your scripts
    • Content-type: text/html; charset=utf-8 in the HTTP header, by way of .htaccess, header() or Web server configuration
    • <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> and <form accept-charset = "utf-8"> in HTML markup
    • CREATE DATABASE … DEFAULT CHARACTER SET utf8 COLLATE utf8 … ENGINE … CHARSET=utf8 
    • COLLATE=utf8_unicode_ci is a typical sequence for a MySQL instance, with comparable expressions for other databases

  • SET NAMES ‘utf8’ COLLATE ‘utf8_unicode_ci’ is a valuable directive for PHP to send MySQL immediately after connecting
  • In php.ini, assign default_charset = UTF-8
  • Replacement of string functions, such as strlen and strtlower, with mb_strlen and mb_convert_case
  • Replacement of mail and colleagues with mb_send_mail, etc.; while Unicode-aware e-mail is an advanced topic beyond the scope of this introduction, the use of mb_send_mail is a good starting point
  • Use of multibyte regular expressions functions (see Resources)
  • Unicode mit/in PHP

    Auf developerworks gibt es einen nützlichen Artikel über Unicode Grundlagen in PHP.

    You’re almost certain to achieve the best results if you focus on this single, consistent target:

    • Explicit use of UTF-8, marked with
      • “mb_language(‘uni’); mb_internal_encoding(‘UTF-8’);” at the top of your scripts
      • Content-type: text/html; charset=utf-8 in the HTTP header, by way of .htaccess, header() or Web server configuration
      • and in HTML markup
      • CREATE DATABASE … DEFAULT CHARACTER SET utf8 COLLATE utf8 … ENGINE … CHARSET=utf8 COLLATE=utf8_unicode_ci is a typical sequence for a MySQL instance, with comparable expressions for other databases
      • SET NAMES ‘utf8’ COLLATE ‘utf8_unicode_ci’ is a valuable directive for PHP to send MySQL immediately after connecting
      • In php.ini, assign default_charset = UTF-8
    • Replacement of string functions, such as strlen and strtlower, with mb_strlen and mb_convert_case
    • Replacement of mail and colleagues with mb_send_mail, etc.; while Unicode-aware e-mail is an advanced topic beyond the scope of this introduction, the use of mb_send_mail is a good starting point
    • Use of multibyte regular expressions functions

    UTF-8 Survival Guide

    Harry Fuecks Hot PHP UTF-8 tips sind das Resultat der Diskussion um seine Slides Scripters UTF-8 Survival Guide (pdf 340 kb)

    Moral of the story…

    …is it’s worth talking to people who actually need UTF-8, vs. those in countries complacently using ISO-8859-1 (which doesn’t natively support the Euro symbol BTW!).

    via phpdeveloper



    Copyright © 2004–2009. All rights reserved. – Impressum

    RSS Feed. This blog is proudly powered by Wordpress and uses Modern Clix, a theme by Rodrigo Galindez.