Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

displaying contents of text file

Posted on 2003-12-04
3
Medium Priority
?
208 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 560 total points
ID: 9879548
u have explode variable wrong.
it should be
explode("|",$row);

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

926 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