Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Reading from txt file

 
   Database Forums (Home) -> PHP RSS
Next:  Derived column design question  
Author Message
FayeC

External


Since: Nov 17, 2005
Posts: 2



(Msg. 1) Posted: Tue Nov 29, 2005 11:37 am
Post subject: Reading from txt file
Archived from groups: comp>lang>php (more info?)

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"

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?

Thank you for any help,

FayeC

 >> Stay informed about: Reading from txt file 
Back to top
Login to vote
Sjoerd

External


Since: Nov 28, 2005
Posts: 11



(Msg. 2) Posted: Tue Nov 29, 2005 11:37 am
Post subject: Re: Reading from txt file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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.

 >> Stay informed about: Reading from txt file 
Back to top
Login to vote
FayeC

External


Since: Nov 17, 2005
Posts: 2



(Msg. 3) Posted: Tue Nov 29, 2005 3:41 pm
Post subject: Re: Reading from txt file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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 :
username="familyname"
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....

Thanks,

FayeC

On 29 Nov 2005 10:29:23 -0800, "Sjoerd" wrote:

>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.
 >> Stay informed about: Reading from txt file 
Back to top
Login to vote
Meião

External


Since: Oct 27, 2005
Posts: 3



(Msg. 4) Posted: Wed Nov 30, 2005 7:28 am
Post subject: Re: Reading from txt file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

try

$data = file('clientlist.txt');
foreach ($data as $line){
$names = explode('=', $line);
print_r($names);
}
 >> Stay informed about: Reading from txt file 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
UTF-8 file reading and writing for PHP - I'm creating a page that: - accepts user input in whatever language - saves that input to a file - reads the file and displays the original input The following code successfully writes the user input to a file (when I open the file, it's in the..

PHP reading extra file info... - I am an ameture digital photographer (along with a newbie developer) and I've an album of my pictures online. I've been building this album to be just how I want it and I've come to one last feature that I can't figure out. How do I read the extra..

Simple text file reading codes NOT working - My PHP code to read a simple text file is listed below. What could have gone wrong here? When I run it, the browser displays: 'COULD NOT Read' opton of the fread() function. I thought the code was OK. <?php $visitorFile="counter.txt&q...

Reading a cookie - I did try to find the answer to this before posting, so this isn't a knee jerk reaction. What I am trying to accomplish is to have a script that opens a cookie, reads a value, and then use a switch/case to take action based on that value in the cookie. ...

Reading remote Session ID - Hi there I have just spent some time re-done a form on my on my site, I have added one of those random images. Please can somebody tell me if what I am doing is correct, the reason I ask I was under the impression you could not read a session ID..
   Database Forums (Home) -> PHP All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]