I have a page where onclick on a button displays the text content from the file in the text area on the page
javascript function
function displayOutput()
{
<?php
$logfile = "hello";
$fh = fopen($logfile, 'r');
$size = filesize($logfile);
if($size == 0)
{
echo "Log file is getting generated";
}
else{
$theData = fread($fh, $size);
$data = trim($theData);
}
fclose($fh);
?>
var html = "<?php echo $data; ?>";
document.form.text1.value = html;
}
Using this function i am able to correctly display the file contents only if the file contains a single line.
I want to display multiple lines in the textarea. I tried removing $data = trim($theData) but then no output is seen. If i echo $theData i am able to see all the file contents but in a single line. I also tried using while(!feof(filename)) but even that didn't work.
How do i display all the contents of the file on a new line using javascript?