Complete and utter noob here, trying to use the contents of input.txt as a string variable
Only snippet I've found that seems to resemble what I need ....
<?php
$filename="input.txt";
$output="";
$file = fopen($filename, "r");
while(!feof($file)) {
$output = $output . fgets($file, 4096);
}
fclose ($file);
echo $output;
?>
So, can I merely use the $output variable to insert a string into my script?
Or is there a better method?
Many Thanks,
Kirk
How do I read .txt file and use contents as string variable
Moderator: General Moderators
-
calvinmicklefinger
- Forum Newbie
- Posts: 10
- Joined: Thu May 03, 2007 2:50 pm
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: How do I read .txt file and use contents as string variable
file() if you want to read all the lines into an array, or
file_get_contents() if you want to read the file into a string.
file_get_contents() if you want to read the file into a string.
-
calvinmicklefinger
- Forum Newbie
- Posts: 10
- Joined: Thu May 03, 2007 2:50 pm