Sort: Date

How To Read a File in Binary Mode
How To Read a File in Binary Mode? - PHP Script Tips - Reading and Writing Files If you have a file that stores binary data, like an executable program or picture file, you need to read the file in binary mode to ensure that none of the data gets modified during the reading process. You need to: Ope...
2007-04-23, 5304👍, 0💬

How To Write a String to a File with a File Handle
How To Write a String to a File with a File Handle? - PHP Script Tips - Reading and Writing Files If you have a file handle linked to a file opened for writing, and you want to write a string to the file, you can use the fwrite() function. It will write the string to the file where the file pointer ...
2007-04-23, 5092👍, 0💬

How To Read One Line of Text from a File
How To Read One Line of Text from a File? - PHP Script Tips - Reading and Writing Files If you have a text file with multiple lines, and you want to read those lines one line at a time, you can use the fgets() function. It reads the current line up to the "\n" character, moves the file pointer to th...
2007-04-22, 5063👍, 0💬

How To Read a Text File into an Array
How To Read a Text File into an Array? - PHP Script Tips - Reading and Writing Files If you have a text file with multiple lines, and you want to read those lines into an array, you can use the file() function. It opens the specified file, reads all the lines, puts each line as a value in an array, ...
2007-04-22, 4850👍, 0💬

How To Append New Data to the End of a File
How To Append New Data to the End of a File? - PHP Script Tips - Reading and Writing Files If you have an existing file, and want to write more data to the end of the file, you can use the fopen($fileName, "a") function. It opens the specified file, moves the file pointer to the end of the file, and...
2007-04-22, 4849👍, 0💬

How To Open Standard Output as a File Handle
How To Open Standard Output as a File Handle? - PHP Script Tips - Reading and Writing Files If you want to open the standard output as a file handle yourself, you can use the fopen("php://stdout") function. It creates a special file handle linking to the standard output, and returns the file handle....
2007-04-23, 4842👍, 0💬

How To Read One Character from a File
How To Read One Character from a File? - PHP Script Tips - Reading and Writing Files If you have a text file, and you want to read the file one character at a time, you can use the fgetc() function. It reads the current character, moves the file pointer to the next character, and returns the charact...
2007-04-22, 4837👍, 0💬

How To Write a String to a File without a File Handle
How To Write a String to a File without a File Handle? - PHP Script Tips - Reading and Writing Files If you have a string, want to write it to a file, and you don't want to open the file with a file handle, you can use the file_put_contents(). It opens the specified file, writes the specified string...
2007-04-23, 4759👍, 0💬

How To Read the Entire File into a Single String
How To Read the Entire File into a Single String? - PHP Script Tips - Reading and Writing Files If you have a file, and you want to read the entire file into a single string, you can use the file_get_contents() function. It opens the specified file, reads all characters in the file, and returns them...
2007-04-22, 4732👍, 0💬

How To Open a File for Reading
How To Open a File for Reading? - PHP Script Tips - Reading and Writing Files If you want to open a file and read its contents piece by piece, you can use the fopen($fileName, "r") function. It opens the specified file, and returns a file handle. The second argument "r" tells PHP to open the file fo...
2007-04-22, 4704👍, 0💬

What's Wrong with "while ($c=fgetc($f)) {}"
What's Wrong with "while ($c=fgetc($f)) {}"? - PHP Script Tips - Reading and Writing Files If you are using "while ($c=fgetc($f)) {}" to loop through each character in a file, the loop may end in the middle of the file when there is a "0" character, because PHP treats "0" as Boolean false. To proper...
2007-04-22, 4703👍, 0💬

How To Read Data from Keyborad (Standard Input)
How To Read Data from Keyborad (Standard Input)? - PHP Script Tips - Reading and Writing Files If you want to read data from the standard input, usually the keyboard, you can use the fopen("php://stdin") function. It creates a special file handle linking to the standard input, and returns the file h...
2007-04-23, 4675👍, 0💬

How To Write an Array to a File without a File Handle
How To Write an Array to a File without a File Handle? - PHP Script Tips - Reading and Writing Files If you have an array, want to write it to a file, and you don't want to open the file with a file handle, you can use the file_put_contents(). It opens the specified file, writes all values from the ...
2007-04-23, 4645👍, 0💬

How To Open a File for Writing
How To Open a File for Writing? - PHP Script Tips - Reading and Writing Files If you want to open a new file and write date to the file, you can use the fopen($fileName, "w") function. It creates the specified file, and returns a file handle. The second argument "w" tells PHP to open the file for wr...
2007-04-22, 4608👍, 0💬

  Sort: Date