Solved

displaying contents of text file

Posted on 2003-12-04
3
195 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
ID: 9879342
what error u are getting.
if u getting undefined variable. then try post before print.
0
 
LVL 1

Author Comment

by:skylabel
ID: 9879449
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
ID: 9879548
u have explode variable wrong.
it should be
explode("|",$row);

0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

832 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