extranet/includes/utils.php

113 lines
2.2 KiB
PHP
Raw Normal View History

2009-03-04 16:38:47 +00:00
<?php
if ( !function_exists('supprDecimales') )
{
function supprDecimales($dec) {
if ($dec>0 )
return floor($dec);
else
2009-03-04 16:38:47 +00:00
return ceil($dec);
}
}
if ( !function_exists('dec2dms') )
{
function dec2dms($dec) {
$d = supprDecimales($dec);
$m = supprDecimales(($dec - $d) * 60);
$s = abs(round(((($dec - $d) * 60) - $m) * 60));
2009-03-04 16:38:47 +00:00
$m = abs($m);
return $d.'<27>'.$m."'".$s.'"';
}
}
function charset2html($str) {
return $str;
if (isUTF8($str))
return '(UTF-8) '.htmlentities($str, ENT_QUOTES, 'UTF-8');
else
return '(non UTF-8) : '.htmlentities($str);
}
function isUTF8($string)
{
return (utf8_encode(utf8_decode($string)) == $string);
}
/**
* Convertit la chaine UTF8 en ISO-8859-1 (si elle est d<EFBFBD>j<EFBFBD> en ISO, ne fait rien!)
*
* @param string $sUtf8 chaine UTF-8 <EFBFBD> convertir en ISO-8859-1
2009-03-04 16:38:47 +00:00
* @return string
*/
function utf8ToIso($sChaineUtf8) {
// Chaine retourn<72>e
$sChaineIso = '';
// D<>tection de l'encodage de la chaine
2009-03-04 16:38:47 +00:00
$sEncodage = mb_detect_encoding($sChaineUtf8,'UTF-8, ISO-8859-1');
// Conversion si chaine n'est pas d<>j<EFBFBD> en ISO-8859-1
if ($sEncodage != 'ISO-8859-1') {
2009-03-04 16:38:47 +00:00
// Encodage
$sChaineIso = mb_convert_encoding($sChaineUtf8, 'ISO-8859-1',$sEncodage);
2009-03-04 16:38:47 +00:00
return $sChaineIso;
}
else {
return $sChaineUtf8;
}
2009-03-04 16:38:47 +00:00
}
2009-03-04 16:38:47 +00:00
/**
* Convertit la chaine ISO-8859-1 en UTF-8 (si elle est d<EFBFBD>j<EFBFBD> en UTF-8, ne fait rien!)
*
* @param string $sChaineIso chaine au format ISO-8859-1
2009-03-04 16:38:47 +00:00
* @return string
*/
function isoToUtf8 ($sChaineIso) {
2009-03-04 16:38:47 +00:00
// Chaine retourn<72>e
$sChaineUtf8 = '';
// D<>tection de l'encodage de la chaine
2009-03-04 16:38:47 +00:00
$sEncodage = mb_detect_encoding($sChaineIso,'UTF-8, ISO-8859-1');
// Conversion si chaine n'est pas d<>j<EFBFBD> en UTF-8
if ($sEncodage != 'UTF-8') {
2009-03-04 16:38:47 +00:00
// Encodage
$sChaineUtf8 = mb_convert_encoding($sChaineIso, 'UTF-8',$sEncodage);
return $sChaineUtf8;
}
else {
return $sChaineIso;
}
}
function moneyKM($number){
if($number!=0){
$i=0;
while(abs($number/1000)>1){
$number=$number/1000;
if($i==2) break;
$i++;
}
switch($i){
case 1: $unite = ' K'; break;
case 2: $unite = ' M'; break;
}
return number_format($number, 0, '', ' ').$unite;
}
2009-03-04 16:38:47 +00:00
}
2009-08-05 14:31:43 +00:00
function deviseText($dev){
switch($dev){
case 'EUR': $return = '&euro;'; break;
default: $return = $dev;
}
return $return;
}
2009-03-04 16:38:47 +00:00
?>