denoteone Posted March 17, 2010 Share Posted March 17, 2010 I am calling a shell script that should return a tab delimited file in a variable name $results but when I write result to a file the only thing that is written is ARRAY and when I use serialize() and then write it to a file it add a whole bunch of special characters. exec("path_to_Shell_script",$results); $myFile = "data.csv"; $fh = fopen($myFile, 'w'); fwrite($fh, $results); fclose($fh); Any help with getting a tab delimited csv file out of this would be great. Quote Link to comment https://forums.phpfreaks.com/topic/195602-exec-help/ Share on other sites More sharing options...
DavidAM Posted March 17, 2010 Share Posted March 17, 2010 If you write an array like that, you get the word "array" as output. Since $results is an array of lines, you will need to use a loop to write it -- something like this: foreach ($results as $line) { fwrite($fh, $line); } Depending on whether or not the line-feeds are still on the lines after input, you may have to add them to the output. If you try the above and everything is on one line then change the write to: fwrite($fh, $line) . PHP_EOL; You might be able to write it with a single command (getting rid of the fopen() and fclose() calls) by using file_put_contents(). Take a look at the PHP documentation http://us.php.net/manual/en/function.file-put-contents.php Quote Link to comment https://forums.phpfreaks.com/topic/195602-exec-help/#findComment-1027787 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.