As in PHPWord add line breaks?

I Use PHPWord. Took the document template and set values in variables.

So did the line breaks and try to frame it in the document:
foreach ($employees as $program => $employee) {
 $employee_string = $employee_string . $nc->q($employee[$program], NCL::$DATELN) . ', ';

 foreach ($employee as $single) {
 $empList = htmlspecialchars($empList . $single . '<br>');
}

 $programs_and_employees = htmlspecialchars($programs_and_employees . '"' . $programs[$program] . '"' . '<br>' . $empList . '<br>');
 }


And in response to receiving <br><br>
Without htmlspecialchars document does not open at all and gives an error. How to fix?
July 8th 19 at 15:32
3 answers
July 8th 19 at 15:34
Solution
I replaced the br on \n
And then replace \n:
$programs_and_employees = str_replace("\n", "<w:br>", $programs_and_employees);</w:br>

And htmlspecialchars was not mandatory
July 8th 19 at 15:36
$text = "foo\nbar\nfoobar";
$textlines = explode("\n", $text);

$textrun = $section->addTextRun();
$textrun->addText(array_shift($textlines));
foreach($textlines as $line) {
$textrun->addTextBreak();
 // maybe twice if you want to seperate the text
 // $textrun->addTextBreak(2);
$textrun->addText($line);
}

https://github.com/PHPOffice/PHPWord/issues/553#is...
July 8th 19 at 15:38
Try PHP_EOL
Didn't work - carroll_Kohler73 commented on July 8th 19 at 15:41

Find more questions by tags PHP