Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

displaying contents of text file

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

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.

715 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