473,569 Members | 2,789 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read a file of string into what?

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
3 1997
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
In article <pa************ *************** *@nowhere.com>,
Konan <kn*******@nowh ere.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
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="textinput form" cols="30" rows="5"><?php echo $contents;
?></textarea>

assuming you know all about forms.

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1849
by: pisscot | last post by:
Lind Apr 13, 6:32 am show options Newsgroups: comp.lang.c From: piss...@gmail.com (Lind) - Find messages by this author Date: 13 Apr 2005 06:32:15 -0700 Local: Wed,Apr 13 2005 6:32 am Subject: how to read it out using c++ Reply | Reply to Author | Forward | Print | Individual Message | Show original | Remove | Report Abuse
22
13221
by: Jason Heyes | last post by:
Does this function need to call eof after the while-loop to be correct? bool read_file(std::string name, std::string &s) { std::ifstream in(name.c_str()); if (!in.is_open()) return false; char c; std::string str;
1
4295
by: Magix | last post by:
Hi, I have these string data: str_data1, str_data2, str_data3, which capture some value after a routine process A. Then I would like to write (append) these 3 string values into a text file each time after routine process A, the text file is named "mytext.dat" in following format with "#####" as separator. The maximum entries of them is...
4
2723
by: ESPN Lover | last post by:
Below is two snippets of code from MSDN showing how to read a file. Is one way preferred over the other and why? Thanks. using System; using System.IO; class Test { public static void Main()
5
3290
by: lovecreatesbea... | last post by:
The condition at line 31 is added to check if the program finished to read the whole file. Is it needed and correct? Thank you. #include <fstream> #include <iostream> #include <string> using namespace std; int read(string filename, int last_pos) {
3
1798
by: Ray | last post by:
Hello World, I made a Windowsform that reads data from a CSV file. It works fine, but when I have read the data of a record I have to re-Debug the form to read another record. So when I put a new seek item in the textbox after I searched for an item and click the seek button.. it seems it is doing nothing. And also... what code can I use...
9
7374
by: flebber | last post by:
I was working at creating a simple program that would read the content of a playlist file( in this case *.k3b") and write it out . the compressed "*.k3b" file has two file and the one I was trying to read was maindata.xml . I cannot however seem to use the gzip module correctly. Have tried the program 2 ways for no success, any ideas would be...
6
5693
by: arnuld | last post by:
This works fine, I welcome any views/advices/coding-practices :) /* C++ Primer - 4/e * * Exercise 8.9 * STATEMENT: * write a program to store each line from a file into a * vector<string>. Now, use istringstream to read read each line * from the vector a word at a time.
5
11238
by: dm3281 | last post by:
Hello, I have a text report from a mainframe that I need to parse. The report has about a 2580 byte header that contains binary information (garbage for the most part); although there are a couple areas that have ASCII text that I need to extract. At the end of the 2580 bytes, I can read the report like a standard text file. It should have...
2
5318
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi Is there any way to Read an INIFile from a string or Stream instead of a physical file ??? I want to read the INIFile into a string then store in a db but when I read the string from the db or save string to the db I don't want to have to copy the string to a file to use the WritePrivateProfileString and GetPrivateProfileString. Is...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8120
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7968
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6283
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.