0

I have a textarea and I want to open a text file and read it inside this textarea, I was watching a course explaining how we can do this and I wrote the cods as he wrote it in the video ,but there is a problem because the words in the file do not appear in the textarea, can anyone help me? ... HTML :

<form>
<h1>Write:</h1>  
<textarea ><?PHP  echo $text;  ?></textarea>   
<button>POST</button>   
</form>

PHP codes :

<?php
$text="";
if($_SERVER['REQUEST_METHOD']=='POST'){ 
$myfile= fopen("myfile.txt","r");
$text= fread($myfile,filesize("myfile.txt"));  
fclose($myfile);       
}
?>

And i put All of them in the body

Aseel.kkh
  • 1
  • 3

1 Answers1

0

use file_get_contents() function to read content of file like below

$data = file_get_contents($path);

set file content in textarea

echo '<textarea>' . htmlspecialchars($data). '</textarea>';
sandip bharadva
  • 629
  • 1
  • 6
  • 19