Subversion Repositories Applications.framework

Rev

Rev 220 | Rev 240 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 220 Rev 235
Line 1... Line 1...
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
 * Classe fournissant des méthodes statiques concernant l'encodage et le décodage Unicode de variable.
4
 * Classe fournissant des méthodes statiques concernant l'encodage et le décodage des caractères de variable.
5
 *
5
 *
6
 * @category	PHP 5.2
6
 * @category	PHP 5.2
7
 * @package	Utilitaire
7
 * @package	Utilitaire
8
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
8
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
9
 * @copyright	Copyright (c) 2009, Tela Botanica (accueil@tela-botanica.org)
9
 * @copyright	Copyright (c) 2009, Tela Botanica (accueil@tela-botanica.org)
10
 * @license	http://www.gnu.org/licenses/gpl.html Licence GNU-GPL-v3
10
 * @license	http://www.gnu.org/licenses/gpl.html Licence GNU-GPL-v3
11
 * @license	http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2 
11
 * @license	http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2 
12
 * @version	SVN : $Id$
12
 * @version	SVN : $Id$
13
 * @link		/doc/framework/
13
 * @link		/doc/framework/
14
 */
14
 */
15
class Unicode {
15
class Encodage {
16
	/**
16
	/**
17
	 * Méthode permettant d'encoder par défaut de ISO-8859-15 vers UTF-8 une variable ou un tableau de variables.
17
	 * Méthode permettant d'encoder par défaut de ISO-8859-15 vers UTF-8 une variable ou un tableau de variables.
18
	 *
18
	 *
19
	 * @param mixed la chaine ou le tableau à encoder en UTF-8 depuis ISO-8859-15.
19
	 * @param mixed la chaine ou le tableau à encoder en UTF-8 depuis ISO-8859-15.
20
	 * @param string l'encodage d'origine si ce n'est pas ISO-8859-15.
20
	 * @param string l'encodage d'origine si ce n'est pas ISO-8859-15.
21
	 * @return mixed la chaine ou le tableau encodé en UTF-8.
21
	 * @return mixed la chaine ou le tableau encodé en UTF-8.
22
	 * @access protected
22
	 * @access protected
23
	 */
23
	 */
24
	public static function encoderUtf8(&$variable, $encodage = 'ISO-8859-15') {
24
	public static function encoderEnUtf8(&$variable, $encodage = 'ISO-8859-15') {
25
		//echo print_r($variable, true)."\n";
25
		//echo print_r($variable, true)."\n";
26
		if (is_array($variable)) {
26
		if (is_array($variable)) {
27
			foreach ($variable as $c => $v) {
27
			foreach ($variable as $c => $v) {
28
				$variable[$c] = self::encoderUtf8($v);
28
				$variable[$c] = self::encoderEnUtf8($v);
29
			}
29
			}
30
		} else {
30
		} else {
31
			// Nous vérifions si nous avons un bon encodage UTF-8
31
			// Nous vérifions si nous avons un bon encodage UTF-8
32
			if (!is_numeric($variable) && !empty($variable) && !self::detecterUtf8($variable)) { 
32
			if (!is_numeric($variable) && !empty($variable) && !self::detecterUtf8($variable)) { 
33
				// Les nombres, les valeurs vides et ce qui est déjà en UTF-8 ne sont pas encodés.
33
				// Les nombres, les valeurs vides et ce qui est déjà en UTF-8 ne sont pas encodés.