Reading from txt file

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have the following code:
$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:

I need the outputString to be what is between the "" and not the
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

Thank you for any help,


Re: Reading from txt file

I don't know what $username is, so your explanation of what you want to
do is not clear. Please describe your problem better.

Furthermore, you can look into the file_get_contents function and the
foreach construct. It will make your code more readable.

Re: Reading from txt file

Sorry....the username is the first part of the line in the txt file:
user1, user2, user3, etc....
Those are just hypotetical 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 :
And then parsing the "familyname" out of the 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....



Quoted text here. Click to load it

Re: Reading from txt file


$data = file('clientlist.txt');
foreach ($data as $line){
  $names = explode('=', $line);

Site Timeline