File input/output: Difference between revisions

Content added Content deleted
(Added Go)
Line 1,021: Line 1,021:
<lang php><?php
<lang php><?php


if (!$in=fopen('input.txt','r')) {
if (!$in = fopen('input.txt', 'r')) {
die('Could not open input.txt!');
die('Could not open input file.');
}
}


if (!$out=fopen('output.txt','w')) {
if (!$out = fopen('output.txt', 'w')) {
die('Could not open output.txt!');
die('Could not open output file.');
}
}


while(!feof($in)) {
while (!feof($in)) {
$data = fread($in,512);
$data = fread($in, 512);
fwrite($out,$data);
fwrite($out, $data);
}
}


Line 1,040: Line 1,040:
{{works with|PHP|5}}
{{works with|PHP|5}}
<lang php><?php
<lang php><?php
if( $contents = file_get_contents('input.txt') ){
if ($contents = file_get_contents('input.txt')) {
if( !file_put_contents('output.txt',$contents) ) echo('could not write output file');
if (!file_put_contents('output.txt', $contents)) {
echo('Could not write output file.');
}else{
}
echo('could not open input file');
} else {
echo('Could not open input file.');
}
}
?></lang>
?></lang>