|
-
Jun 30th, 2002, 02:56 PM
#1
Thread Starter
Fanatic Member
Reading strings from file
Ok, what I am trying to do is read a set of values from a file. For example:
1=stuff
2=more stuff
Now, this is the code I am using to get the values:
PHP Code:
<?
$pFile = fopen ("data.txt","r");
while ($info = fscanf($pFile, "%d=%s\n"))
{
list($first, $second) = $info;
echo $first . ": " . $second . "<br>";
}
fclose($pFile);
?>
However, the problem is, it only reads up to the whitespace, so I get "more" for the second line instead of "more stuff." How do I take in spaces too?
Alcohol & calculus don't mix.
Never drink & derive.
-
Jul 1st, 2002, 12:51 AM
#2
Stuck in the 80s
I'm probably going to throw you off here, but I'd do this:
PHP Code:
$contents = file("data.txt");
for ($i = 0; $i < count($contents); $i++) {
$parts = explode("=", $contents[$i]);
echo $parts[0] . ":" . $parts[1] . "<br>";
}
Of course that'd only work if all the lines in your file are #=something.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|