473,789 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read a full text file

Mague
137 New Member
I have got a website with a few friends from school(year8). We have got a website up. I want it so it looks for a textfile and reads and writes it into a textbox. It does do this. The only problem is that it doesn't read the whole file. It may read like 3 words out of 7 so its not that gud.

This is my code
Expand|Select|Wrap|Line Numbers
  1. <div id="text2" style="position:absolute; overflow:hidden; left:351px; top:192px; width:475px; height:671px; z-index:2"><div class="wpmd">
  2. <div><font class="ws12" face="Franklin Gothic Heavy">
  3. <?php
  4. $myFile = "HomeNews.txt";
  5. $passw = fopen($myFile, "r");
  6. $pass = fread($passw, 5);
  7. while ( $line = fgets($passw, 1000) ) {
  8. echo($line);
  9. }
I am using notepad on windows xp. And im using my friends server which he pays for and i think they use appach.

Hopefully someone can help.
Thanks alot
Mague
Aug 10 '07 #1
4 1848
nathj
938 Recognized Expert Contributor
[php]
<div id="text2" style="position :absolute; overflow:hidden ; left:351px; top:192px; width:475px; height:671px; z-index:2"><div class="wpmd">
<div><font class="ws12" face="Franklin Gothic Heavy">
<?php
$myFile = "HomeNews.t xt";
$passw = fopen($myFile, "r");
$pass = fread($passw, 5);
while ( $line = fgets($passw, 1000) ) {
echo($line);
}
[/php]
Mague
Try changing the line:
[php]
$pass = fread($passw, 5) ;
[/php]

To:
[php]
$pass = fread($passw, filesize($passw ))
[/php]

I found this on the php site. There maybe more helpful information there.

Cheers
nathj
Aug 10 '07 #2
Mague
137 New Member
Try changing the line:
[php]
$pass = fread($passw, 5) ;
[/php]

To:
[php]
$pass = fread($passw, filesize($passw ))
[/php]

I found this on the php site. There maybe more helpful information there.

Cheers
nathj
Thanks Alot this code didn't work but led me on to find this code
$contents = fread($handle,f ilesize); which does work

thanks heaps
Mague
Aug 10 '07 #3
nathj
938 Recognized Expert Contributor
Thanks Alot this code didn't work but led me on to find this code
$contents = fread($handle,f ilesize); which does work

thanks heaps
Mague

that;s my mistake - the filesize function takes the filename as the parameter not the file handle - that's my fault. Sorry, at least it's working now though.

All the best with the rest of the project.

Cheers
nathj
Aug 10 '07 #4
pbmods
5,821 Recognized Expert Expert
Heya, Mague.

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.
Aug 13 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

19
2524
by: ranjeet | last post by:
Hay Guys can you all suggest me the points on the below issue Problem : The thing is that I have the data some thing like this. 1486, 2168, 3751, 9074, 12134, 13944, 17983, 19173, 21190, 21820, 1730, 2640, 3450, 4870, 6126, 7876, 15644, 17817, 20294, 21902, 2070, 3025, 4333, 5854, 7805, 9231, 10597, 16047........................... soo onnnnnn
4
2161
by: Kueishiong Tu | last post by:
I have a text file with wide characters. I use the following C++ code to read them in. However the wide characters are not read in properly. What is wrong? String* path = "C:\\Documents and Settings\\kst\\BE.dat"; try { FileStream* fs = new FileStream(path, FileMode::Open); StreamReader* sr = new StreamReader(fs);
0
683
by: Jerry | last post by:
Below is ALL the code for all the databases... Here's the problem: I callup the aspx file in IE and the form comes up just fine. When I select a person to update, I get the subject error. Aparently, when I select a person, it's not selecting anyone and returning this error. Here's the full error: Description: An unhandled exception occurred during the execution of the
4
1338
by: Ernesto | last post by:
I'm just want to read in the contents of a (text) file. The text file is filled with semiColon delimited floating point strings... 0.456;1.265;99.742;... For some reason, I can't get the contents back when I call file.read() Here's my code. filePath = "C:\\folder\\myFile.txt fileHandle = open(filePath, 'r').read();
7
2153
by: sweetpotatop | last post by:
Hello, I have a txt file which has a few lines of special characters: This is A line from the text file: ٦-ŧُʍѥޘ²ů'ۣб'с ',,طꎏЏ׮ When I use sr.ReadLine (where "sr As StreamReader"), it is not giving me this line
6
32919
by: Thomas Kowalski | last post by:
Hi, currently I am reading a huge (about 10-100 MB) text-file line by line using fstreams and getline. I wonder whether there is a faster way to read a file line by line (with std::string line). Is there some way to burst read the whole file and later "extract" each line? Thanks in advance, Thomas Kowalski
2
5519
by: RyanS09 | last post by:
Hi- I have read many posts with specific applications of reading in text files into arrays, however I have not been able to successfully modify any for my application. I want to take a text file filled with a tab delimited list of 10 columns (floats) and read it into a 2D array. The length of the columns are all the same, however this will be variable from text file to text file. Any help (starter code or where to read) would be much...
6
5717
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.
3
3032
by: VK | last post by:
On Apr 21, 1:54 pm, joe <m...@invalid.comwrote: http://www.jibbering.com/faq/index.html#FAQ4_18
1
9363
by: Matrixinline | last post by:
Hi All, File Text.txt Contains following text as : "C:\program file\application data\details\app" "D:\Program File" I tried to read that data as fscanf(oFp, "%s %s", sCopyDirectory, sToDirectory);
0
9499
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10374
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10177
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9969
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8995
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7519
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5539
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2898
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.