Subversion Repositories Applications.framework

Compare Revisions

Ignore whitespace Rev 234 → Rev 235

/trunk/framework/utilitaires/Unicode.php
File deleted
\ No newline at end of file
/trunk/framework/utilitaires/Encodage.php
New file
0,0 → 1,57
<?php
// declare(encoding='UTF-8');
/**
* Classe fournissant des méthodes statiques concernant l'encodage et le décodage des caractères de variable.
*
* @category PHP 5.2
* @package Utilitaire
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
* @copyright Copyright (c) 2009, Tela Botanica (accueil@tela-botanica.org)
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL-v3
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2
* @version SVN : $Id$
* @link /doc/framework/
*/
class Encodage {
/**
* Méthode permettant d'encoder par défaut de ISO-8859-15 vers UTF-8 une variable ou un tableau de variables.
*
* @param mixed la chaine ou le tableau à encoder en UTF-8 depuis ISO-8859-15.
* @param string l'encodage d'origine si ce n'est pas ISO-8859-15.
* @return mixed la chaine ou le tableau encodé en UTF-8.
* @access protected
*/
public static function encoderEnUtf8(&$variable, $encodage = 'ISO-8859-15') {
//echo print_r($variable, true)."\n";
if (is_array($variable)) {
foreach ($variable as $c => $v) {
$variable[$c] = self::encoderEnUtf8($v);
}
} else {
// Nous vérifions si nous avons un bon encodage UTF-8
if (!is_numeric($variable) && !empty($variable) && !self::detecterUtf8($variable)) {
// Les nombres, les valeurs vides et ce qui est déjà en UTF-8 ne sont pas encodés.
$variable = mb_convert_encoding($variable, 'UTF-8', $encodage);
}
}
return $variable;
}
/**
* Méthode permettant de détecter réellement l'encodage UTF-8.
* mb_detect_encoding plante si la chaine de caractère se termine par un caractère accentué.
* Provient de PHPDIG.
*
* @param string la chaine à vérifier.
* @return bool true si c'est de UTF-8, sinon false.
* @access private
*/
public static function detecterUtf8($chaine) {
if ($chaine === mb_convert_encoding(mb_convert_encoding($chaine, 'UTF-32', 'UTF-8'), 'UTF-8', 'UTF-32')) {
return true;
} else {
return false;
}
}
}
?>
/trunk/framework/utilitaires/Chaine.php
New file
0,0 → 1,68
<?php
// declare(encoding='UTF-8');
/**
* Classe fournissant des méthodes statiques de manipulation des chaînes de caractères (String).
*
* @category PHP 5.2
* @package Utilitaire
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
* @copyright Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL-v3
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2
* @version $Id$
* @link /doc/framework/
*/
class Chaine {
 
private static $caracteres_accentues = array(
'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î',
'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß',
'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î',
'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'Ā',
'ā', 'Ă', 'ă', 'Ą', 'ą', 'Ć', 'ć', 'Ĉ', 'ĉ', 'Ċ', 'ċ', 'Č', 'č', 'Ď', 'ď',
'Đ', 'đ', 'Ē', 'ē', 'Ĕ', 'ĕ', 'Ė', 'ė', 'Ę', 'ę', 'Ě', 'ě', 'Ĝ', 'ĝ', 'Ğ',
'ğ', 'Ġ', 'ġ', 'Ģ', 'ģ', 'Ĥ', 'ĥ', 'Ħ', 'ħ', 'Ĩ', 'ĩ', 'Ī', 'ī', 'Ĭ', 'ĭ',
'Į', 'į', 'İ', 'ı', 'IJ', 'ij', 'Ĵ', 'ĵ', 'Ķ', 'ķ', 'Ĺ', 'ĺ', 'Ļ', 'ļ', 'Ľ',
'ľ', 'Ŀ', 'ŀ', 'Ł',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J', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l',
'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R',
'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't',
'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y',
'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I',
'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o');
/**
* Supprime ou remplace les accents d'une chaine en PHP.
* La solution retenu, provenant du site
* {@link http://www.lecoindunet.com/zone_php/scripts_utiles/remplacer-les-caracteres-accentues-dune-chaine-en-php-72 lecoindunet.com},
* consiste en deux tableaux (caractères avec et sans accents) car cela permetra éventuellement
* de fournir des méthodes pour récupérer ces tableaux pour d'autres traitements.
* Une autre solution aurait été d'utiliser les entités HTML comme proposé par le site
* {@link http://www.weirdog.com/blog/php/supprimer-les-accents-des-caracteres-accentues.html weirdog.com}.
*
* @param String $chaine la chaine de caractères dans laquelle supprimer les accents.
* @param String $encodage le code d'encodage de la chaine si ce n'est pas de l'UTF-8.
* @return la chaine de caractères sans accent.
*/
function supprimerAccents($chaine, $encodage = 'UTF-8') {
if ($encodage != 'UTF-8') {
mb_convert_variables($encodage, 'UTF-8', self::$caracteres_accentues, self::$caracteres_normaux);
}
return str_replace(self::$caracteres_accentues, self::$caracteres_normaux, $chaine);
}
}
?>