Solved

displaying contents of text file

Posted on 2003-12-04
3
204 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

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.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

631 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