2GB limit on file size when using fwrite in C?

On a 32 bits system (i.e. the OS is 32 bits), by default, fopen and co are limited to 32 bits size/offset/etc… You need to enable the large file support, or use the *64 bits option: http://www.gnu.org/software/libc/manual/html_node/Opening-Streams.html#index-fopen64-931 Then your fs needs to support this, but except fat and other primitive fs, all of them support … Read more

fwrite() and UTF8

If you know the data is in UTF8 than you want to set up the header. I wrote a solution answering to another tread. The solution is the following: As the UTF-8 byte-order mark is \xef\xbb\xbf we should add it to the document’s header. <?php function writeStringToFile($file, $string){ $f=fopen($file, “wb”); $file=”\xEF\xBB\xBF”.$file; // this is what … Read more

Overwrite Line in File with PHP

If the file is really big (log files or something like this) and you are willing to sacrifice speed for memory consumption you could open two files and essentially do the trick Jeremy Ruten proposed by using files instead of system memory. $source=”in.txt”; $target=”out.txt”; // copy operation $sh=fopen($source, ‘r’); $th=fopen($target, ‘w’); while (!feof($sh)) { $line=fgets($sh); … Read more