Fichier .txt => Tableau Array() ?

Nouveau WRInaute
Bonjour, pouvez vous m'aidé car je suis débutant
je peux lire mon fichier mais je souhaiterais le faire dans un tableau en récupérant certaines lignes du fichier.Merci
Code:
<?php


$bdd = NEW PDO('mysql:host=localhost;dbname=server_statut','root','', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$reponse = mysqli_init("SELECT * FROM server_statut");




$url="http://aventureclub-airlines.fr/whazzup/whazzup.txt";
$tab = file($url);
$start = FALSE;
foreach ($tab as $line) {
	$line = trim($line);
	if ($line == '') { break; }
 
   if ($start) {
		print_r(explode(':',$line));
   }
 
   if ($line == '!CLIENTS') {
	   $start = TRUE;
	   echo 'GO';
   }
   elseif ($line == '!SERVERS') {
	   $start = FALSE;
   }
}




?>

Sa donne sa:
GOArray ( [0] => LFFF_CTR [1] => ATC [2] => Aventureclub AIRLINES [3] => ATC [4] => 128.10 [5] => 48.713056 [6] => 2.418888 [7] => [8] => [9] => [10] => [11] => [12] => [13] => [14] => -AventureClub- [15] => 0.0.4.H [16] => 11 [17] => [18] => 6 [19] => 700 [20] => [21] => [22] => [23] => [24] => [25] => [26] => [27] => [28] => [29] => [30] => [31] => [32] => [33] => [34] => [35] => No Atis * 212.227.107.53 Port 8767/LFFF_CTR [36] => [37] => 20140713115211 [38] => DafRadar [39] => 0.0.4.H [40] => 11 [41] => 10 [42] => [43] => [44] => [45] => [46] => ) Array ( [0] => ACF13 [1] => ACF13 [2] => Jean-louis [3] => PILOT [4] => 122.800 [5] => 29.302073 [6] => -10.647657 [7] => 36796 [8] => 463 [9] => T/E170/F [10] => 350 [11] => GMML [12] => 370 [13] => GMMN [14] => -AventureClub- [15] => 0.0.4.X [16] => 10 [17] => 2014 [18] => [19] => [20] => [21] => I [22] => 0000 [23] => 0000 [24] => 0 [25] => 0 [26] => 0 [27] => 0 [28] => GMME [29] => [30] => SOLNA UA600 ADM UG850 MAK UR722 CSD [31] => [32] => [33] => [34] => [35] => [36] => [37] => 20140713075043[38] => Daf*FSX [39] => 0.0.4.X [40] => 1 [41] => 10 [42] => [43] => [44] => 1 [45] => 52 [46] => 0 ) Array ( [0] => ACF01[1] => ACF01[2] => Denis BOUS [3] => PILOT [4] => 122.80 [5] => 42.697582 [6] => 13.558798 [7] => 37259 [8] => 483 [9] => T/B787/F [10] => 470 [11] => LFRS [12] => 370 [13] => LGAV [14] => -AventureClub- [15] => 0.0.4.X [16] => 12 [17] => 1200 [18] => [19] => [20] => [21] => I [22] => 0000 [23] => 0000 [24] => 0 [25] => 0 [26] => 0 [27] => 0 [28] => NONE [29] => [30] => LUGEN UM616 BEBIX UP860 MEDAM UM730 KUMIN UM730 KODOK UM730 FRZ UM872 VALEN UZ904 PREKI UQ920 PES UM872 DIVKU UP92 BRD UL995 KRK UL53 PIKAD [31] => [32] => [33] => [34] => [35] => [36] => [37] => 20140713095031 [38] => Daf*XP10 [39] => 0.0.4.X [40] => 12 [41] => 10 [42] => [43] => [44] => 198 [45] => 120 [46] => 0 ) Array ( [0] => !SERVERS )...
En couleurs,c'est ce que je veux récupérer "vert colonne: Online controleurs champs:ATC,Name,frequency et en bleu pour une colonne: Online Pilotes champs:Callsign,Name,FS .;) la liste change en fonction des membres connecter sur le server [3] => ATC et[4] => PILOT clé primaire pour mes colonnes
Merci de votre aide
 
WRInaute impliqué
Code:
$url="http://aventureclub-airlines.fr/whazzup/whazzup.txt";
$file = file($url);
$connect = array();
foreach ($file as $line) {
   $line = trim($line);
if(preg_match("/([^:]+)\:([^:]+)\:([^:]+)....../", $line, $matches){
$connect[] = array($matches[2], $matches[7] ....);
}
}

en adaptant l'expression régulière au contenu, et la ligne pour récuperer les valeurs à la bonne position.
 
Nouveau WRInaute
Merci d'avoir répondu aussi vite :wink:

j'ai une erreur
Code:
Parse error: syntax error, unexpected '{' in D:\Program Files (x86)\wamp\www\Server_Statut\index.php on line 16
Code:
 
Nouveau WRInaute
j'ai ajouté ) après $matches) et j'ai à nouveau une erreur
Parse error: syntax error, unexpected '.' in D:\Program Files (x86)\wamp\www\Server_Statut\index.php on line 17
]

$url="http://aventureclub-airlines.fr/whazzup/whazzup.txt";
$file = file($url);
$connect = array();
foreach ($file as $line) {
$line = trim($line);
if(preg_match("/([^:]+)\:([^:]+)\:([^:]+)....../", $line, $matches)){
$connect[] = array($matches[2], $matches[7] ....);
}
}
 
WRInaute passionné
T'as vraiment laissé cette ligne en l'état ?
$connect[] = array($matches[2], $matches[7] ....);

Les points c'est pour dire de compléter je pense.. non? Pareil pour les points du dessus.. D'accord je lis que tu es débutant, mais jamais il peut y avoir des points comme ça dans une déclaration d'une array()

D'ailleurs loubet dit : "en adaptant l'expression régulière au contenu, et la ligne pour récuperer les valeurs à la bonne position." c'est juste une piste et non le code final.
 
Nouveau WRInaute
Salut,

voici mon code:
Code:
<HEAD>
<meta http-equiv='refresh' content='60;url='http://localhost/Server_Statut/'>
</HEAD>


<?php


$bdd = NEW PDO('mysql:host=localhost;dbname=server_statut','root','', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$reponse = mysqli_init("SELECT * FROM server_statut");




$url="http://aventureclub-airlines.fr/whazzup/whazzup.txt";
$file = file($url);
$connect = array();
foreach ($file as $line) {
   $line = trim($line);
if(preg_match("/([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)/", $line, $matches )){
$connect[] = array($matches[2], $matches[3], $matches[12], $matches[14], $matches[15], $matches[16] );
}
}




echo "<pre>"; var_dump($connect); echo "</pre>";

$url="http://aventureclub-airlines.fr/whazzup/whazzup.txt";
$file = file($url);
$connect = array();
foreach ($file as $line) {
   $line = trim($line);
if(preg_match("/([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)/", $line, $matches )){
$connect[] = array($matches[1], $matches[3], $matches[5] );
}
}




echo "<pre>"; var_dump($connect); echo "</pre>";

?>

le problème c'est que j'aimerais affiché la ligne [39] après la [16] mais j'ai une erreur :roll: et je peux pas ajouter plus de
Code:
\:([^:]+)
y y t'il une solution merci d'avance
 
Nouveau WRInaute
Re bonjour, j'ai enfin réussi à obtenir mon script mais j'ai un petit souci impossible le lire toute la chaine de caractère! le dois récupérer une valeur mais j'ai une erreur offset
comment faire? merci

voici le code:
Code:
<style type="text/css">
.style2 {
	text-align: center;
	font-size: small;
	color: #00FF00;
	background-color: #FFFFFF;
	border-left-color: #A0A0A0;
	border-right-color: #C0C0C0;
	border-top-color: #A0A0A0;
	border-bottom-color: #C0C0C0;
}
.style3 {
	text-align: center;
	font-size: x-small;
	background-color: #66FF99;
	white-space: nowrap;
}
.style33 {
	font-size: x-small;
	font-weight: bold;
	background-color: #000000;
}
.style40 {
	border-style: solid;
	border-color: #81DAF5;
	font-size: x-small;
	text-align: center;
	color: #0F0F10;
	background-color: #81DAF5;
	font-family: Raavi;
	white-space: nowrap;
	font-weight: normal;
}

.style44 {
	border-style: solid;
	border-color: #3366FF;
	font-size: small;
		text-align: center;
		color: #FFFFFF;
	background-color: #3366FF;
		font-family: Raavi;
		font-weight: normal;
		text-decoration: blink;
	}
.style46 {
	border-style: solid;
	border-color: #3366FF;
	font-size: x-small;
	text-align: center;
	color: #FFFFFF;
	background-color: #3366FF;
	font-family: Raavi;
	text-decoration: blink;
}
</style>
<meta content="3" name="arr" />
</head>

<body style="background-attachment: fixed">

<table cellpadding="3" cellspacing="3" class="style33" style="float: left" align="left">
	<caption></caption>
	<tr>
		<td style="width: 352px"class="style40">


<head>
<meta content="fr" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<!-- #BeginEditable "doctitle" -->

<!-- #EndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="../common.css" type="text/css">
<link rel="stylesheet" href="CSS/form.style.css" type="text/css">
<link rel="stylesheet" href="CSS/table_table_jui.css" type="text/css">
<link rel="stylesheet" href="CSS/cupertino/jquery-ui-1.9.2.custom.min.css" type="text/css">
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery-ui-1.9.2.custom.min.js" type="text/javascript"></script>
<script src="js/dafsimform.js" type="text/javascript"></script>
<script src="js/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="js/jquery.form.js" type="text/javascript"></script>
<script src="js/jquery.validate.min.js" type="text/javascript"></script>
<style type="text/css">
<style type="text/css">
.style2 {
	text-align: center;
	font-size: small;
	color: #00FF00;
	background-color: #000000;
	border-left-color: #A0A0A0;
	border-right-color: #C0C0C0;
	border-top-color: #A0A0A0;
	border-bottom-color: #C0C0C0;
}
.style3 {
	text-align: center;
	font-size: x-small;
	background-color: #66FF99;
	white-space: nowrap;
}
.style33 {
	font-size: x-small;
	font-weight: bold;
	background-color: #000000;
}
.style40 {
	border-style: solid;
	border-color: #B2D0FE;
	font-size: x-small;
	text-align: center;
	color: #000000;
	background-color: #B2D0FE;
	font-family: Raavi;
	white-space: nowrap;
	font-weight: normal;
}



</style><meta content="3" name="arr" />
<title>Statut Server AventureClub Airlines</title>
</head>

<body style="margin: 5; background-attachment: fixed">

<table cellspacing="1" class="style43" style="float: none; width: 915px; height: 790px; z-index: 24; position: absolute; top: 2px; left: 2px;" align="center">
	<caption></caption>
	<tr>
		<th style="width: 903px; height: 48px;"class="style40">


<head>
<meta content="fr" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<!-- #BeginEditable "doctitle" -->

<!-- #EndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="../common.css" type="text/css">
<link rel="stylesheet" href="CSS/form.style.css" type="text/css">
<link rel="stylesheet" href="CSS/table_table_jui.css" type="text/css">
<link rel="stylesheet" href="CSS/cupertino/jquery-ui-1.9.2.custom.min.css" type="text/css">
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery-ui-1.9.2.custom.min.js" type="text/javascript"></script>
<script src="js/dafsimform.js" type="text/javascript"></script>
<script src="js/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="js/jquery.form.js" type="text/javascript"></script>
<script src="js/jquery.validate.min.js" type="text/javascript"></script>
<style type="text/css">
<style type="text/css">
.style2 {
	text-align: center;
	font-size: small;
	color: #00FF00;
	background-color: #000000;
	border-left-color: #A0A0A0;
	border-right-color: #C0C0C0;
	border-top-color: #A0A0A0;
	border-bottom-color: #C0C0C0;
}
.style3 {
	text-align: center;
	font-size: x-small;
	background-color: #66FF99;
	white-space: nowrap;
}
.style40 {
	border-style: solid;
	border-color: #B2D0FE;
	font-size: x-small;
	text-align: center;
	color: #000000;
	background-color: #B2D0FE;
	font-family: Raavi;
	white-space: nowrap;
	font-weight: normal;
}



</style>
<style type="text/css">
.style3 {
	border-left-style: solid;
	border-left-width: 3px;
	border-right: 3px solid #C0C0C0;
	border-top-style: solid;
	border-top-width: 3px;
	border-bottom: 3px solid #C0C0C0;
}
.style41 {
	border: 3px solid #000000;
}
.style43 {
	font-size: x-small;
	font-weight: bold;
	border: 3px solid #000000;
	background-color: #000000;
	margin-top: 1px;
	margin-right: 0px;
}
.style44 {
	margin-left: 0px;
	margin-top: 0px;
}
.style46 {
	font-size: x-small;
	text-align: center;
	color: #FFFFFF;
	font-family: Raavi;
	text-decoration: blink;
	border: 1px solid #3366FF;
	margin-top: 0px;
	background-color: #3366FF;
}
</style>


<table class="style41" style="width: 909px; height: 46px; z-index: 1; position: absolute; top: 6px; left: 1px;">
	<tr>
	<th class="style3" ><div class="annonce">
		<marquee onmouseover="this.stop()" onmouseout="this.start()" direction="left" scrollamount="5" style="width: 868px; height: 35px;"><span style="color: #DC143C; font-size: 20px; font-family: Raavi text-shadow: 0px 0px 10px LUEUR QUI ENTOURE LE TEXTE;"><img src="http://aventureclub-airlines.fr/ImageACF/Banni%C3%A8re%20ACF%20Aventureclub%20Airlines.jpg85x18%20copy.gif">   Rejoignez-nous avec votre simulateur de vol: FS9, FSX, Xplane9, XPlane10, Prepar3D et partagez de bons moments ensemble   <img src="http://aventureclub-airlines.fr/ImageACF/Banni%C3%A8re%20ACF%20Aventureclub%20Airlines.jpg85x18%20copy.gif"></span></marquee></div></th>
	</tr>
</table>









<table align="center" class="style46" cellpadding="0" cellspacing="0">
	<tr style="z-index: 1; position: absolute; top: 57px; left: 13px">
		<th class="style47">
		<iframe src="http://www.dafsim.com/map/?va=-AventureClub-&amp;output=embed" frameborder="3" marginwidth="3" marginheight="3" scrolling="no" class="style44" style="width: 877px; height: 718px; z-index: 1; position: absolute; top: 8px; left: 0px; float: center;" align="middle" name="Map"></iframe>
		<table cellpadding="0" cellspacing="0" class="style2" style="z-index: 1; width: 362px; height: 64; position: absolute; top: 514px; left: 265px">
	<tr>
		<td style="width: 339px"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="fr" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<!-- #BeginEditable "doctitle" -->

<!-- #EndEditable -->
<style type="text/css">
.style2 {
	border: 3px solid #000000;
	text-align: center;
		font-size: small;
		color: #00FF00;
	background-color: #C0C0C0;
	}
.style3 {
	text-align: center;
	font-size: x-small;
	background-color: #66FF99;
	white-space: nowrap;	
}
.style30 {
	color: #00FF00;
	font-size: 13px;
	border-left-color: #A0A0A0;
	border-left-width: 0;
	border-right-color: #C0C0C0;
	border-right-width: 0;
	border-top-color: #A0A0A0;
	border-top-width: 0;
	border-bottom-color: #C0C0C0;
	border-bottom-width: 0;
	background-color: #000000;
.style33 {
	font-size: x-small;
	font-weight: bold;
	background-color: #000000;
}
.style40 {
	border-style: solid;
	border-color: #81DAF5;
	font-size: x-small;
	text-align: center;
	color: #0F0F10;
	background-color: #81DAF5;
	font-family: Raavi;
	white-space: nowrap;
	font-weight: normal;
}
.style44 {
	border-style: solid;
	border-color: #3366FF;
	font-size: small;
		text-align: center;
		color: #FFFFFF;
	background-color: #3366FF;
		font-family: Raavi;
		font-weight: normal;
		text-decoration: blink;
	}
.style46 {
	border-style: solid;
	border-color: #3366FF;
	font-size: x-small;
	text-align: center;
	color: #FFFFFF;
	background-color: #3366FF;
	font-family: Raavi;
	text-decoration: blink;
}
</style>
<meta content="3" name="arr" />
</head>

<body style="background-attachment: fixed">

<table cellpadding="0" cellspacing="0" class="style33" style="float: left" align="left">
	<caption></caption>
	<tr>
		<td style="width: 356px; height: 19px;"class="style69">


<head>
<meta content="fr" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<!-- #BeginEditable "doctitle" -->

<!-- #EndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="../common.css" type="text/css">
<link rel="stylesheet" href="CSS/form.style.css" type="text/css">
<link rel="stylesheet" href="CSS/table_table_jui.css" type="text/css">
<link rel="stylesheet" href="CSS/cupertino/jquery-ui-1.9.2.custom.min.css" type="text/css">
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery-ui-1.9.2.custom.min.js" type="text/javascript"></script>
<script src="js/dafsimform.js" type="text/javascript"></script>
<script src="js/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="js/jquery.form.js" type="text/javascript"></script>
<script src="js/jquery.validate.min.js" type="text/javascript"></script>
<style type="text/css">
<style type="text/css">
.style2 {
	text-align: center;
	font-size: small;
	color: #00FF00;
	background-color: #000000;
	border-left-color: #A0A0A0;
	border-right-color: #C0C0C0;
	border-top-color: #A0A0A0;
	border-bottom-color: #C0C0C0;
}
.style3 {
	text-align: center;
	font-size: x-small;
	background-color: #66FF99;
	white-space: nowrap;
}
.style33 {
	font-size: x-small;
	font-weight: bold;
	background-color: #000000;
}
.style40 {
	border-style: solid;
	border-color: #B2D0FE;
	font-size: x-small;
	text-align: center;
	color: #000000;
	background-color: #B2D0FE;
	font-family: Raavi;
	white-space: nowrap;
	font-weight: normal;
}

.style34 {
	font-size: x-small;
	background-color: #000000;
}


.style47 {
	border: 1px solid #FFFFFF;
	font-size: x-small;
		font-weight: bold;
		background-color: #FFFFFF;
}


.style69 {
	font-size: x-small;
	color: #000000;
	font-family: Raavi;
	white-space: nowrap;
	font-weight: normal;
	border-style: solid;
	border-color: #B2D0FE;
	background-color: #B2D0FE;
}


</style>



<HEAD>  
    <meta http-equiv='refresh' content='60;url='http://localhost/Server_Statut.php/'>  

</HEAD>

 
<?php
$bdd  = NEW PDO('mysql:host=localhost;dbname=server_statut','root','', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$url  = "http://aventureclub-airlines.fr/whazzup/whazzup.txt";
$file = file($url);
$connect = array();
foreach ($file as $line)
{
    $line = trim($line);
    if(false != preg_match("/([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:]+)\:([^:DafWings*]+)/", $line, $matches))
    {
        $connect[] = array(
		    $matches[1],
            $matches[2],
            $matches[3],
            $matches[12],
            $matches[14],
			$matches[10],
        );
    }
}

/**
 * Ouverture du tableau HTML
 */
$sTableau  = <<<CODE_HTML
        <table>
        <thead>
		<tr>
		<th class="style15" colspan="6" style="height: 31px" valign="middle">
		<div>
		</div>
		<span class="style34">&nbsp;</span><span class="style30" style="height: 31px">Pilotes et Controleurs en Ligne</span></th>
	</tr>
	    <tr>
        <th class="style3" style="height: 9px; width: 7px;">Fonction</th>
		<th class="style3" style="height: 9px; width: 2px;">Callsign</th>
		<th class="style3" style="height: 9px; width: 150px;">Name</th>
		<th class="style3" style="height: 9px; width: 33px;">Depart</th>
		<th class="style3" style="height: 9px; width: 31px;">Arrivee</th>
		<th class="style3" style="height: 9px; width: 9px;">Aircraft</th>
            </tr>

          </thead>
          <tbody>

CODE_HTML;

/**
 * Construction des lignes du tableau
 */
foreach($connect as $ligne):
    $Fonction       = htmlentities($ligne[0]);
    $callsign   = htmlentities($ligne[1]);
    $name       = htmlentities($ligne[2]);
    $depart     = htmlentities($ligne[3]);
    $arrivee    = htmlentities($ligne[4]);
	$Aircraft   = htmlentities($ligne[5]);
    $sTableau .= <<<CODE_HTML
            <tr>
			  <td class="style40" style="height: 9px; width: 9px;">{$Fonction}</td>
              <td class="style40" style="height: 9px; width: 9px;">{$callsign}</td>
              <td class="style40" style="height: 9px; width: 9px;">{$name}</td>
              <td class="style40" style="height: 9px; width: 9px;">{$depart}</td>
              <td class="style40" style="height: 9px; width: 9px;">{$arrivee}</td>
			  <td class="style40" style="height: 9px; width: 9px;">{$Aircraft}</td>
            </tr>

CODE_HTML;

endforeach;

/**
 * Fermeture du tableau HTML
 */
$sTableau .= <<<CODE_HTML
          </tbody>
        </table>

CODE_HTML;


$sTableau .= <<<CODE_HTML
          </tbody>
        </table>

CODE_HTML;

/**

 * Affichage du tableau HTML
 */
echo($sTableau);

?>
</table>
		</th>
	</tr>
	</table>
 
Discussions similaires
Haut