I have a program (written in cpp) which outputs some text lines. Each line starts on a new line. On the commandline this program works well. To test the code I used both fprintf (stdout, "some text\n"); and 'cout << "some text" << endl;' to produce newlines.
When I use passthru or shell_exec in a php-script, the newlines disappear - as expected - in my webbrowser. The newlines do appear when I use curl, though (which is good):
$command = "/home/test/myprogram 2>&1";
$data = shell_exec ( $command );
echo $data;
To print the newlines in the webbrowser, I tried lots of php code to replace newlines with
tags, but nothing seems to work, including examples from a related SO question (PHP New Line Not Working):
echo nl2br($data);
echo str_replace(array("\r\n","\r","\n"),'<br>',$data);
I guess the failure has to to with my usage of passthru or shell_exec, but I can't figure how to solve my issue.