0

i don't know how to refresh a textarea.
if i have a text file opened on this textarea and i entre some lines into this file, i want to refresh my textarea in ..second automaticaly ..to see the new lines..

<textarea id="chat" rows='38' cols='189'>
<?php
$file1 = "test.txt";
$file2 = fopen($file1,"r");
while(! feof($file2))
  {
  echo fgets($file2)."<br/>";
  }
fclose($file2);
?>
</textarea>

i need help please

2
Contributors
8
Replies
26
Views
3 Years
Discussion Span
Last Post by gabrielcastillo
0

You need to user asynchronous javascript for this to happen.. Take a look at jquery. This is a good library to start with.

0

I can create a solution using jquery, as you can too.

what do you mean, you want to refresh the textarea? Is this after save the file or as you are editing the file? You can create a function with php to opend and edit a file, and then use ajax to call the function and load the saved data.

0

i want to refresh the textarea after saving some lines into the text file
(the text file is opened into the textarea,so after editing this file the new lines appears into the textarea)

0

my code open & show all lines into "test.txt",
so the problem is, if i add some lines into my file i can't see the new lines into the textarea before i refresh the page... i want to refresh just the textarea to show all new lines thats it :)

<textarea id="tt" rows='38' cols='189'>
<?php
$file1 = "test.txt";
$file2 = fopen($file1,"r");
while(! feof($file2))
  {
  echo fgets($file2)."<br/>";
  }
fclose($file2);
?>
</textarea>
0

my code open & show all lines into "test.txt",
so the problem is, if i add some lines into my file i can't see the new lines into the textarea before i refresh the page... i want to refresh just the textarea to show all new lines thats it :)

<textarea id="tt" rows='38' cols='189'>
<?php
$file1 = "test.txt";
$file2 = fopen($file1,"r");
while(! feof($file2))
  {
  echo fgets($file2)."<br/>";
  }
fclose($file2);
?>
</textarea>
0

Looks like you are having trouble working it out so I will make an attempt for you.

This should open your file, allow you to edit the file, and save to the file.

Place all this code in one page.

<?php
    function insert_records($input)
    {
        $file = "test.txt";
        $fh = fopen($file, 'w') or die("can't open file");
        fwrite($fh, $input);
        fclose($fh);  
        return true;  
    }

    function read_records()
    {
        $handle = @fopen("test.txt", "r");
        if ($handle) {
            while (($buffer = fgets($handle, 4096)) !== false) {
                echo $buffer;
            }
            if (!feof($handle)) {
                echo "Error: unexpected fgets() fail\n";
            }
            fclose($handle);
        }
    }

    if( isset($_POST['save_file']) ){
       $updated = insert_records($_POST['editor']);   
       if($updated == true){
        echo 'file has been updated';           
       }else{
        echo 'file has not been updated';
       }
    }



?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p><textarea name="editor" rows="30" cols="100"><?php read_records(); ?></textarea></p>
<p><input type="submit" name="save_file" value="Save Changes" /></p>
</form> 
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.