Error writing to file

Why is it not written to the file?

<?php 
$file = fopen("somefile.txt", r, use_include_path);
$newfile = fopen("somenewfile.txt", "a+", use_include_path);

while (!feof($file)) {
    $content = fgets($file);

    for ($i=0; $i < strlen($content); $i++) { 
        $symbol = substr($content, 0+$i, 1);

            fwrite($newfile, $symbol ." ");             
    }
}
fclose($file);
fclose($newfile);

?> 
Author: Nicolas Chabanovsky, 2015-10-21

1 answers

You have a problem (even two) in the arguments of the function fopen.

1) the mode r in the first use of the function is not in quotation marks

$file = fopen("somefile.txt", r, use_include_path);

And should

$file = fopen("somefile.txt", "r", use_include_path);

2) use_include_path - an optional parameter that can be set to either 1 or TRUE if you also want to search for a file in include_path.

Ie or so

$file = fopen("somefile.txt", "r");
$newfile = fopen("somenewfile.txt", "a+");

Or so

$file = fopen("somefile.txt", "r", true);
$newfile = fopen("somenewfile.txt", "a+", true);
 2
Author: torokhkun, 2015-10-22 05:53:15