I trying to convert a scraped table to csv file. It works fine.
But when I add preg_match to extract only values of tempatures, I got an error:
Array to string conversion in C:\xampp\htdocs\simple_dom\Scrape.php on line 65
Can anyone help me to figure it out?:)
"17,7 �C";"3,0 �C";"12,1 �C";"16,9 �C";"2,9 �C";"-0,8 �C"
"15,6 �C";"2,7 �C";"10,4 �C";"15,0 �C";"3,9 �C";"2,9 �C"
"17,2 �C";"2,2 �C";" ";" ";" ";" "
"16,8 �C";"2,6 �C";"11,5 �C";"15,9 �C";"5,3 �C";"0,8 �C"
$table = $html->find('table');
$Data=array();
$i=0;
$k=1;
foreach(myFind($table,'td') as $cell) {
$tpr= $cell->innertext;
$pattern = "(-?\d{1,2}\,\d)";
preg_match($pattern , $tpr, $match);
$rowData[] =$match;
$i++;
if(fmod($i, 7)==0){
$Data[$k]=array_slice($rowData,1);
$rowData=array();
$k++;
$i=0;
}
}
convertCSV($Data);
function convertCSV($Data){
$fp = fopen('file.csv', 'w');
foreach ($Data as $fields){
fputcsv($fp, $fields, $delimiter = ";");
}
fclose($fp);
}