PHP golfing tips: Reading/writing files and the CLI I have been participating in a number of PHP code golf challenges recently and some of the techniques that are used to read data from a file such as fopen() and fread() or file_get_contents() really give my code a beating on the char count. Especially the methods provided for reading in command line input.

My question is, what is the fastest way (least keystrokes) to read and write to the contents of a file, and what is the fastest way (least keystrokes) to read a line from the prompt? 

(Note: As this is code golf, I can't use any external libraries.)
You can read a line from STDIN in 13 characters:

fgets(STDIN);


as seen here.

Reading from a file:

file('filename')


returns an array of lines of the file.

Using fputs instead of fwrite will save a character on writing, but I can't think of a shorter way than:

fputs(fopen('filename','w')); //use 'a' if you're appending to a file instead of overwriting


which is marginally shorter than:

file_put_contents('filename');