Read a file of string into what?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Pardon the simple question, but I have just begun to learn PHP.  So far so
good - all the examples in my books actually work.

One thing that none of them address is how to read a file of strings (like
names or URLs or whatever) into something so that they can be deleted,
modified or a new one added.  In a language like Perl/TK or Delphi a
listbox is used if you want to edit line by line or a memo box if you want
to edit like you are in Kwrite.  

All the examples assume that I want to enter data into a Text area or
Listbox by keyboard, then read it back in.  Never the other way around.  I
can use a Fget routine and read the file to the screen, but not to
anything in which I can edit yet.

So far I have learned a ton of stuff trying, but haven't made it work yet.

Should I be reading the data into a Textarea, a Listbox or something else?

Anybody got a short example.


Re: Read a file of string into what?

Have a look at php manuel. You can download it from But i
think this will work for you.

$handle = fopen(" /", "rb");
$contents = '';
while (!feof($handle)) {
 $contents .= fread($handle, 8192);

<input type="text" value="<?php echo $contents; ?>">

Re: Read a file of string into what?

Quoted text here. Click to load it

You have a file consisting of lines of text.  fgets(HANDLE) will return
a line at a time into a variable.  So you use it within a loop and store
into an array.  Now you have an array who's elements contain the lines
of your file.  You can do whatever you want to the that array with the
various array manipulation functions and output whatever you wish in

What's the problem you're trying to solve?  I'm confused here.

DeeDee, don't press that button!  DeeDee!  NO!  Dee...

Re: Read a file of string into what?

I think you mean this:
$handle = fopen("filename","rt"); // where filename is a file on the
$contents = "";
while (!feof($handle))
  $contents .= fgets($handle);
<textarea name="textinputform" cols="30" rows="5"><?php echo $contents;

assuming you know all about forms.

Site Timeline