Joshua Ott February 2016

Export CSV: Illegal string offset

I am attempting to write a CSV export with this PHP code:

header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=' . $project_name . ' - ' . $milestone_title . '.csv');
$output = '"MILESTONE";"ISSUE";"TAG";"ASSIGNEE";"STATE";"WORKING TIME"' . "\n";
foreach ($_SESSION['milestones'][$milestone_id] as $issue) {
    $output .= '"' . $issue['milestone']['title'] . '";"' . $issue['title'] . '";"' . $issue['labels'] . '";"' . $issue['assignee']['name'] . '";"' . $issue['state'] . '";"' . $issue['working_time']['hours'] . '"' . "\n";
}
echo $output;
exit;

I get the following output when I try to generate a CSV using this code, including a number of warnings:

<b>Warning</b>:  Illegal string offset 'milestone' in <b>C:\xampp\htdocs\gitlab\src\controllers.php</b> on line <b>135</b><br />
<br />
<b>Warning</b>:  Illegal string offset 'title' in <b>C:\xampp\htdocs\gitlab\src\controllers.php</b> on line <b>135</b><br />
<br />
<b>Warning</b>:  Illegal string offset 'title' in <b>C:\xampp\htdocs\gitlab\src\controllers.php</b> on line <b>135</b><br />
<br />
<b>Warning</b>:  Illegal string offset 'labels' in <b>C:\xampp\htdocs\gitlab\src\controllers.php</b> on line <b>135</b><br />
<br />
<b>Warning</b>:  Illegal string offset 'assignee' in <b>C:\xampp\htdocs\gitlab\src\controllers.php</b> on line <b>135</b><br />
<br />
<b>Warning</b>:  Illegal string offset 'name' in <b>C:\xampp\htdocs\gitlab\src\controllers.php</b> on line <b>135</b><br />
<br />
<b>Warning</b>:  Illegal string offset 'state' in <b>C:\xampp\htdocs\gitlab\src\controllers.php</b> on line <b>135</b><        

Answers


Joshua Ott February 2016

Thanks for helping!

I was wrong with my milestones array

Post Status

Asked in February 2016
Viewed 3,505 times
Voted 7
Answered 1 times

Search




Leave an answer