[thelist] parsing txt file?

Flavia Tarzwell (FayeC) ftarzwell at fayec.com
Tue Nov 29 17:59:58 CST 2005


I have the following code:
<?php
$username = $_POST['username'];
$myFile = "clientlist.txt";
$fp = fopen($myFile, 'r');
$content = fread( $fp, filesize( $myFile ) );
$inputString = $username;

$arrFp = file( $myFile ); // Open the data file as an array
$numLines = count( $arrFp ); // Count the elements in the array

$arrWords = explode( ' ', $inputString ); // Split the input string
into words as an array
$numWords = count( $arrWords ); // Count the words in the string

for($i=0; $i<$numWords; $i++) // Loop through the words in the string
{
    for($j=0; $j<$numLines; $j++) // Loop through the lines of the
text file
    $outputString .= $arrWords[$i].' ';
}
?>

And I need it to read a txt file that has something like:
user1="Smith"
user2="Macintosh"
user3="Hogan"
The $username is the first part of the line in the txt file:
user1, user2, user3, etc....
Those are just hypothetical and being used for testing purposes.
The login is a simple login using POST and the page receiving the POST
data is a page where images are displayed.
I was abble to just get the variable sent by the form and use that to
display the images since the images are named user1_1.jpg,
user1_2.jpg, etc....
But now I have to find a way to add a line like:
"Welcome to baby "familyname"'s page!"
The "familyname" is not the same as the username so I had the idea of
creating a simple txt file with :
username="familyname"
And then parsing the "familyname" out of the file.
I need the outputString to be what is between the "" and not the
$username....
Right now it is outputting the same as the $username.
How do I change the code to select what is between the "" in the text
file?
The problem is that I was able to parse the username out of the txt
file but not the "familyname"...
How do I get that out of the txt file? Do I use file_get_contents?
I read about it but it didn't make sense since I don't want the whole
file in one single array....

Thanks,

FayeC







More information about the thelist mailing list