1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
|
<?php
/**
* $Id: tools.class,v 1.9 2003/03/26 08:31:39 courou Exp $
*
* Author : courou@users.sourceforge.net
* Website : http://allreponse.ath.cx
*
* Support : http://sourceforge.net/projects/myphpmoney/
* CVS : http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/myphpmoney/
*/
// class qui regroupe differents outils
// @author courou : courou@users.sourceforge.net
// @date 30/09/2002
class Tools {
// Init
function Tools() {
}
// Contruit le header pour le download
// @param $Name = nom du fichier
function Construc_header($nom_of_file) {
header("Content-disposition: filename=".$nom_of_file);
header("Content-type: application/octetstream");
header("Pragma: no-cache");
header("Expires: 0");
}
// Cherche nb mois ecouler entre deux dates
// @param $Month1 = Mois 1
// @param $Month2 = Mois 2
// @param $Year1 = Anne 1
// @param $Year2 = Anne 2
function Nombre_Mois_ecouler($Month1,$Year1,$Month2,$Year2) {
$Date1 = mktime( 0, 0, 0, $Month1,1,$Year1 );
$Date2 = mktime( 0, 0, 0, $Month2,1,$Year2 );
$nbDays = ($Date2 - $Date1) / (60*60*24);
return round($nbDays / 30);
}
// on genere un numero unique
// @param $length = longueur souhaiter
function numero_unique($length) {
return substr(date("U")."".getMyPid(),0,$length);
}
// Ajoute des slashes devant les "
// @param $value = La valeur qui doit etre tester
function add_slashes($value) {
return ereg_replace("\"","\\\"",$value);
}
// @param $chaine = chaine vrifier (String)
// @param $nbmaxcar = combien de chiffre on garde
function Reduit_chaine($chaine,$nbmaxcar,$default=0) {
if (strlen($chaine) > $nbmaxcar) {
return ($default == 0 ? substr($chaine,0,$nbmaxcar)." ..." : substr($chaine,0,$nbmaxcar));
} else {
return $chaine;
}
}
// permet de formater et d'afficher un chiffre
// @param $nombre = chiffre
function formatage($nombre) {
return ($nombre == '0.00' ? 0 : number_format($nombre, 2, '.', ' '));
}
// verifie si connection internet active
function verif_connect() {
Global $_MPM;
preg_match("/^(http:\/\/)?([^\/]+)(.+)/i", $_MPM['external_rate'] , $matches);
$fp = fsockopen ("$matches[2]", 80, $errno, $errstr, 30);
if (!$fp) {
## for Connection refused
$open_url = @ini_get('allow_url_fopen');
if (isset($errno) && isset($open_url) && $errno == '111' && $open_url == 1) {
define('PHP_HOSTCONNECT',1);
}
return false;
} else {
return true;
fclose($fp);
}
return;
}
// Permet d'enlever les commentaires d'un fichier
// @param $sql = fichier a parser et scanner
function Remove_Remarks($sql) {
$i = 0;
while ($i < strlen($sql)) {
if ($sql[$i] == '#' && ($i == 0 || $sql[$i-1] == "\n")) {
$j = 1;
while ($sql[$i+$j] != "\n") {
$j++;
if ($j+$i > strlen($sql)) {
break;
}
} ## end of while
$sql = substr($sql, 0, $i) . substr($sql, $i+$j);
} ## end of if
$i++;
} ## end of while
return $sql;
}
// Cette fonction rcupere l'heure en microsecondes
function getmicrotime() {
list($usec, $sec) = explode(" ", microtime());
return ($usec + $sec);
}
// Supprimer les accents d'une chaine
// Trouver sur phpinfo.net
// @param $strings = la chaine a remplacer
function Del_accent($strings) {
$tab = array
(
"" => "Y", "" => "u", "" => "A", "" => "A", "" => "A", "" => "A",
"" => "A", "" => "A", "" => "A", "" => "C", "" => "E", "" => "E",
"" => "E", "" => "E", "" => "I", "" => "I", "" => "I", "" => "I",
"" => "D", "" => "N", "" => "O", "" => "O", "" => "O", "" => "O",
"" => "O", "" => "O", "" => "U", "" => "U", "" => "U", "" => "U",
"" => "Y", "" => "s", "" => "a", "" => "a", "" => "a", "" => "a",
"" => "a", "" => "a", "" => "a", "" => "c", "" => "e", "" => "e",
"" => "e", "" => "e", "" => "i", "" => "i", "" => "i", "" => "i",
"" => "o", "" => "n", "" => "o", "" => "o", "" => "o", "" => "o",
"" => "o", "" => "o", "" => "u", "" => "u", "" => "u", "" => "u",
"" => "y", "" => "y"
);
return strtr("$strings", $tab);
} ## end of function Del_accent
// Recherche le nombre d'enregistrement d'un fichier grace a un separateur
// @param $sql = fichier a parser et scanner
// @param $delimiter = delimiter le fichier
function Split_Sql_File($sql, $delimiter) {
$sql = trim($sql);
$char = '';
$last_char = '';
$ret = array();
$string_start = '';
$in_string = FALSE;
$escaped_backslash = FALSE;
for ($i = 0; $i < strlen($sql); ++$i) {
$char = $sql[$i];
// if delimiter found, add the parsed part to the returned array
if ($char == $delimiter && !$in_string) {
$ret[] = substr($sql, 0, $i);
$sql = substr($sql, $i + 1);
$i = 0;
$last_char = '';
}
if ($in_string) {
if ($char == '\\') {
if ($last_char != '\\') {
$escaped_backslash = FALSE;
} else {
$escaped_backslash = !$escaped_backslash;
}
}
if (($char == $string_start) && !(($last_char == '\\') && !$escaped_backslash)) {
$in_string = FALSE;
$string_start = '';
}
} else {
if (($char == '"') || ($char == '\'') || ($char == '`')) {
$in_string = TRUE;
$string_start = $char;
}
} ## end of if $in_string
$last_char = $char;
} ## end of for $i
if (!empty($sql)) {
$ret[] = $sql;
}
return $ret;
}
} ## end of class Tools
//Comment utiliser la classe
//Il suffit d'appeler la methode souhaite
//$tools-> = new Tools();
//$tools->Del_accent($strings);
//example
//verifie la connection
//$tools->verif_connect();
function ne_pas_utiliser_tools(){
// effacer cette fonction apres
while(1){};
}
|