Input/Output
document.write("text", variable, "(X)HTML tags", ...);
To output plain text, then wait for click on OK, use:
alert("text" + variable + "\n");
To output plain text, then wait for click on OK or Cancel, use:
confirm("Some question ... ");
prompt("Text of prompt ... ", "default text");
echo "one", "two";
echo ("one");
For output with default formats if you want
to return 1 (success) or 0 (failure) use:
print "one";
For formatted output use:
printf
$outfile_var = fopen("filename", "w");
To open a file for appending output use:
$outfile_var = fopen("filename", "a");
To write to an output file use:
$bytes_written = fwrite($file_var, $out_data);
$infile_var = fopen("filename", "r");
To read an entire textfile into a single string use:
$file_string = fread($infile_var, filesize("filename");
To read an entire textfile into an array of strings use:
$file_lines = file("filename");
To read a line of up to n-1 characters (not including
the newline character) from a textfile, use:
$file_line = fgets($infile_var, 100);
To read a single character from a file, use:
$file_char = fgetc($infile_var);
$inoutfile_var = fopen("filename", "r+");
For reading and writing a (possibly new) file, with
any writing starting at the file beginning
(thus overwriting any existing content), use:
$inoutfile_var = fopen("filename", "w+");
For reading and writing a (possibly new) file, with
any writing taking place at the end of the file, use:
$inoutfile_var = fopen("filename", "a+");
flock($file_var, 1|2|3);
To close an open file use:
fclose($file_var);
print
For formatted output use:
printf
<STDIN>
open(OUTDAT, ">filename");
To open a file for appending output use:
open(OUTDAT, ">>filename");
To print to an output file use:
print OUTDAT "Some string ...";
open(INDAT, "<filename");
To read a line (including the newline character)
from a textfile use:
$line = <INDAT>
To read a line from a binary file use:
read(INDAT, $buffer, length, buffer_offset);
open(INOUTDAT, "+>filename");
To move the read/write "cursor" to a particular
file location use:
seek(INOUTDAT, offset, 0|1|2);
flock(FILE_HANDLE, LOCK_EX);
To close an open file use:
close(FILE_HANDLE);