Solved

displaying contents of text file

Posted on 2003-12-04
3
190 Views
Last Modified: 2009-07-29
PHP newbie here, I've got the following script and I'm trying to display the contents of test.txt. one line per record.

<?php
$array = file("test.txt");
foreach($array as $row) {
   $line = explode($row, "|");
   print "Name: $line[0], Email: $line[1]<br>";
}
?>

test.txt has 2 fields on each line, which looks like
John Doe|john@doe.com
Jane Doe|jane@doe.com
Billy Bob Joe|joe@domain.com

It's not damn working.....why? help appreciated....
0
Comment
Question by:skylabel
  • 2
3 Comments
 
LVL 24

Expert Comment

by:shivsa
Comment Utility
what error u are getting.
if u getting undefined variable. then try post before print.
0
 
LVL 1

Author Comment

by:skylabel
Comment Utility
Basically, my output is as follows (i.e. it doesn't display any of the contents of the text file)

Name: |, Email:
Name: |, Email:
Name: |, Email:

Grrrr....
0
 
LVL 24

Accepted Solution

by:
shivsa earned 140 total points
Comment Utility
u have explode variable wrong.
it should be
explode("|",$row);

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now