Daniel60
07/04/2016, 17h41
Envoyé par Jikoo
[2016-04-07 14:08:01] ## OVH ## START - 2016-04-07 14:08:01.828875 executing: /usr/local/php5.5/bin/php /homez.119/librairim/www/rename.php [2016-04-07 14:08:01] [2016-04-07 14:08:01] ## OVH ## END - 2016-04-07 14:08:01.899967 exitcode: 0
#!/usr/local/bin/php
setlocale(LC_TIME, "fr_FR");
unlink("./data/updatedb.csv");
unlink("./data/stock.csv");
copy("./data/UPDATEDB.TXT", "./data/updatedb.csv");
$newfichier = fopen("./data/sortie_stock.csv", "w");
// crée le fichier cible s'il n'existe pas ou écrase s'il existe déjà
fclose($newfichier);
$lines = file('./data/updatedb.csv'); // ouverture du fichier d'origine
$fp = fopen("./data/stock.csv","w"); //création du fichier de sortie
$tampon = ""; // initialisation de la variable tampon
foreach ($lines as $lineNumber => $lineContent) // boucle pour parcourir le fichier d'origine
{
if (strpos($lineContent,"##" ) !== false) // condition si la ligne contient séparateur
{
$tampon = $tampon . $lineContent; // ajout du contenu de la ligne au tampon
$arr_base = explode(";",$tampon);
$uc_12 = $arr_base[12];
$ucfirst = ucfirst(mb_strtolower($uc_12));
$tampon = str_replace($uc_12,$ucfirst,$tampon);
$uc_13 = $arr_base[13];
$ucfirst = ucfirst(mb_strtolower($uc_13));
$tampon = str_replace($uc_13,$ucfirst,$tampon);
$uc_15 = $arr_base[15];
$ucfirst = ucfirst(mb_strtolower($uc_15));
$tampon = str_replace($uc_15,$ucfirst,$tampon);
$uc_17 = $arr_base[17];
$ucfirst = ucwords(mb_strtolower($uc_17));
$tampon = str_replace($uc_17,$ucfirst,$tampon);
$uc_18 = $arr_base[18];
$ucfirst = ucfirst(mb_strtolower($uc_18));
$tampon = str_replace($uc_18,$ucfirst,$tampon);
$uc_10 = $arr_base[10];
$date = strftime("%d %B %Y", strtotime($uc_10));
$tampon = str_replace($uc_10,$date,$tampon);
fputs($fp,$tampon); // écriture de la ligne tampon dans le fichier
$tampon = ""; // clear du tampon
}else{ // condition si ne contient pas de séparateur
$tampon = $tampon . trim($lineContent); // alors ajoute le contenu au tampon déjà existant
}
}
fclose($fp); // fermeture du fichier
file_put_contents('./data/sortie_stock.csv', file_get_contents('./data/format.csv') . file_get_contents('./data/stock.csv') );
?>