Hey Guys,
So using a webform textarea I am passing some data into PHP.
This data is basically 4 columns of an excel sheet and potentially unlimited rows. Now I want to be able to go through this data, select each of the four individual elements from each row, insert these as a new row into a MySQL database and do this for each row pasted into the original textarea.
I was told that Excel separates new lines with a '\n' character and each column with a '\t' separator. So my approach was to use $rows=explode('\n',$data)
and then explode each of the items in the resulting array using $row=explode('\t',$rows[0])
. This is however not working, and I can't for the life of me figure out why.
This is a sample code which I found on the internet, and which I modelled my code on.
$arrayCode = array();
$rows = explode("\n", $str);
foreach($rows as $idx => $row)
{
$row = explode( "\t", $row );
foreach( $row as $field )
{
$arrayCode[$idx][] = $field;
}
}
print_r( $arrayCode );
If anyone has any inputs on an alternative approach or what I am doing wrong that would be greatly appreciated. Please bear in mind that this data has to be copy pasted into a textarea from an excel document and I cannot import the .xlsx/.xls/.csv file directly into this. Thanks.
Best Regards
Sarovar Chandra