Last active
December 23, 2015 03:29
-
-
Save alancoleman/6573685 to your computer and use it in GitHub Desktop.
Function to create a file, add some content and write out to the browser.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// createFile function | |
function createFile($filename) { | |
// Declare content | |
$content = "Some content here"; | |
$morecontent = "And some more content here"; | |
// Add content to file | |
file_put_contents( | |
$filename, | |
"$content\n$morecontent" | |
); | |
// Message browser | |
echo $filename . " updated.<hr / >"; | |
// Open file, read only | |
$file = fopen($filename, "r") or exit("Unable to open file!"); | |
//Output a line of the file until the end is reached | |
while(!feof($file)) | |
{ | |
echo fgets($file). "<br / >"; | |
} | |
fclose($file); | |
} | |
// Declare file name | |
$createFilename = "file.txt"; | |
// Call function, taking $createFilename as an argument | |
createFile($createFilename); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment