<?php

	//phpinfo();

	error_reporting(0);
	
	header( 'content-type: text/html; charset=utf-8' );

	//header('Content-Type: text/html; charset=iso-8859-1');

	//ISO-8859-1

	include('fonctions.php');
	
	echo "Le blé est haut";
	
function fct()
{	
	//mysql_query("SET NAMES 'utf8'");
	//mysql_set_charset("utf8");
	
	$connexion = DB(); 	
/*	
	$table = "infos_tbl";
	$sql = "INSERT INTO " .$table ." (id, jeu, v1, v2, v3, v4 ) VALUES('', 'jeu' ,'v1' , 'v2' ,'v3', 'v4')"; 
	echo $sql;
	$result = mysqli_query($connexion, $sql );
	if(!$result)
	{
		die('Impossible d\'exécuter la requête :' . mysql_error());
	}
*/
	
		$fileHandle = fopen("liste_jeux.csv", "r");
 
		while (($row = fgetcsv($fileHandle, 0, ";")) !== FALSE) 
		{
		
			//$row[0] = str_replace('!', ' ', $row[0]);
			//$row[0] = str_replace('\'', ' ', $row[0]);
		
			echo 'Nom: ' . $row[0] . '<br>';
			echo '# de joueurs min: ' . $row[1] . '<br>';
			echo '# de joueurs max: ' . $row[2] . '<br>';
			echo 'Durée min: ' . $row[3] . '<br>';
			echo 'durée max: ' . $row[4] . '<br>';
			echo 'Age: ' . $row[5] . '<br>';
			echo '<br>';
			echo '<br>';
			echo '<br>';
			
			//$row[0] = strtr($row[0], 'áàâäãåçéèêëíìîïñóòôöõúùûüýÿ', 'aaaaaaceeeeiiiinooooouuuuyy');
			
			$row[0] = mysql_real_escape_string($row[0]);
			
			$texte = strtr( $texte, 
						'@ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ',
						'aAAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy'
					);

			//$row[0] = utf8_decode($row[0]);		

			//$str = sansAccent($row[0]);			
					
			//mysqli_set_charset($connexion, "utf8");
			//mysqli_set_charset("utf8");
			
		
			//$row[0] = str_replace("é", "e", $row[0] );
		
			//echo $row[0];
			
			//mysql_query("SET NAMES 'utf8'");
			//$row[0] = mysql_real_escape_string($row[0]);
			
			$query = "INSERT INTO table_jeu (id, nom, nb_joueur_min, nb_joueur_max, duration_min, duration_max, age) VALUES ('', '$row[0]', '$row[1]', '$row[2]', '$row[3]', '$row[4]', 'toto')";

			echo $query;
			echo "<br>";
		
			$result = mysqli_query($connexion, $query );
			
			if (!$result)
			{
				die('Requête invalide : ' . mysql_error());
			}
	
		}
	
}

//$str = strtr($str, 'ÁÀÂÄÃÅÇÉÈÊËÍÏÎÌÑÓÒÔÖÕÚÙÛÜÝ', 'AAAAAACEEEEEIIIINOOOOOUUUUY');
//$str = strtr($str, 'áàâäãåçéèêëíìîïñóòôöõúùûüýÿ', 'aaaaaaceeeeiiiinooooouuuuyy');

//utf8_general_ci
// ISO-8859-1 by default


	fct();
	
function sansAccent($chaine)
{   // remplace les caractères accentués par des lettres sans accents
        $chaine= mb_str_replace( "é", "e", $chaine);
        $chaine= mb_str_replace( "è", "e", $chaine);
        $chaine= mb_str_replace( "ê", "e", $chaine);
        $chaine= mb_str_replace( "ë", "e", $chaine);
        $chaine= mb_str_replace( "à", "a", $chaine);
        $chaine= mb_str_replace( "â", "a", $chaine);
        $chaine= mb_str_replace( "ä", "a", $chaine);
        $chaine= mb_str_replace( "ï", "i", $chaine);
        $chaine= mb_str_replace( "î", "i", $chaine);
        $chaine= mb_str_replace( "ô", "o", $chaine);
        $chaine= mb_str_replace( "ö", "o", $chaine);
         
        return $chaine;
}
	
function wd_remove_accents($str, $charset='utf-8')
{
    $str = htmlentities($str, ENT_NOQUOTES, $charset);
    
    $str = preg_replace('#&([A-za-z])(?:acute|cedil|caron|circ|grave|orn|ring|slash|th|tilde|uml);#', '\1', $str);
    $str = preg_replace('#&([A-za-z]{2})(?:lig);#', '\1', $str); // pour les ligatures e.g. '&oelig;'
    $str = preg_replace('#&[^;]+;#', '', $str); // supprime les autres caractères
    
    return $str;
}


function _removeAccents ($text) 
{
        $alphabet = array(
            'Š'=>'S', 'š'=>'s', 'Ð'=>'Dj','Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A',
            'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I',
            'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U',
            'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss','à'=>'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', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', 'ƒ'=>'f',
        );
 
        $text = strtr ($text, $alphabet);
 
        // replace all non letters or digits by -
        $text = preg_replace('/\W+/', '-', $text);
 
        return $text;
}

	
	
/*	
 CREATE TABLE table_jeu
 (
	ID int(10) NOT NULL AUTO_INCREMENT,
	nom varchar(100) not null,
	nb_joueur_min varchar(10) not null,
	nb_joueur_max(10) not null,
	duration_min varchar(10) not null,
	duration_max varchar(10) not null,
	age varchar(10) not null,
	PRIMARY KEY (id)
 );
*/
	
?>