By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,409 Members | 1,604 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,409 IT Pros & Developers. It's quick & easy.

Read a file of string into what?

P: n/a
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.

Thanks
Konan
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


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

$handle = fopen("http://www.example.com/", "rb");
$contents = '';
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);

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

Jul 17 '05 #2

P: n/a
In article <pa****************************@nowhere.com>,
Konan <kn*******@nowhere.com> wrote:
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.

Thanks
Konan


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
HTML.

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

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

Jul 17 '05 #3

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

assuming you know all about forms.

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.