Reverse File Contents
Error: Cannot open $inputFile");
// Read entire file content
$content = '';
while (!feof($inHandle)) {
$content .= fgets($inHandle);
}
fclose($inHandle);
// Reverse the content
$reversedContent = strrev($content);
// Write to output file
$outHandle = fopen($outputFile, 'w') or die("Error: Cannot write to $outputFile
");
fwrite($outHandle, $reversedContent);
fclose($outHandle);
// Display results
echo "
";
echo "Original Content:
";
echo "" . htmlspecialchars($content) . "
";
echo "Reversed Content:
";
echo "" . htmlspecialchars($reversedContent) . "
";
echo "Output also written to file: $outputFile
";
}
?>