<?php
/**
* Formats a text file for manual execution.
* Preserves original content and adds basic formatting.
*
* @param string $filename The path to the text file.
* @return string|false The formatted content as a string, or false on error.
*/
function formatTextFile($filename) {
if (!file_exists($filename)) {
error_log("File not found: " . $filename);
return false;
}
$fileContent = file_get_contents($filename);
if ($fileContent === false) {
error_log("Failed to read file: " . $filename);
return false;
}
// Add a header
$formattedContent = "<?php\n\n/**\n * This code was generated from the file: " . $filename . "\n * Please review and modify as needed.\n */\n\n";
$formattedContent .= $fileContent;
return $formattedContent;
}
// Example usage (uncomment to test)
/*
$formattedCode = formatTextFile("my_script.txt");
if ($formattedCode !== false) {
echo $formattedCode;
// Optionally, write to a new file:
// file_put_contents("formatted_script.php", $formattedCode);
} else {
echo "Formatting failed.";
}
*/
?>
Add your comment