This is my code : $myfile = file_get_contents('/ftpfiles/monitor-data') or die ("Unable"); //$new_array = array_chunk($myfile, 9); //$new_array = array_filter(explode(" ", file_get_contents('/ftpfiles/monitor-data') or die ("Unable"))); //$length = count($new_array); //print_r($new_array) $table = ''; $filearray = explode(" ", $myfile); //var_dump($filearray);
foreach($filearray as $value)
{
$table .= '<tr><td align = "center">'.$value.'</td></tr>';
}
$table.='</table>';
echo $table;
But I am getting just one row, how can I create 9 columns for one row. I tried using Value[0].. value[8] but just broke whole string into single characters.
You should try to explode your rows as well (as you are doing it with the entire file) :
$myfile = file_get_contents('/ftpfiles/monitor-data') or die("Unable");
$table = '<table border="3">';
$filearray = explode(" ", $myfile);
foreach($filearray as $row) {
// here separate your row that is a string, into an array
$cols = explode(" ", $row);
$table .= '<tr>';
foreach($cols as $value) {
$table .= '<td align = "center">'.$value.'</td>';
}
$table .= '</tr>';
}
$table.='</table>';
echo $table;
Of course, that implies that all your rows will explode in the same amount of columns. If you monitor-data file differs from one line to another, you should adapt the code to parse each row.