Hello everyone, i am new here. Hmm...can you all please help me with this..what is the code for reading lines from a text file..Thanks =)
15 7139 ak1dnar 1,584
Recognized Expert Top Contributor
Hello everyone, i am new here. Hmm...can you all please help me with this..what is the code for reading lines from a text file..Thanks =)
Hi, Fab108 Welcome to TSDN.
Try these Tutorials
Thanks for your help, but fgets help us to get the first line for example my text file is
Datalogs:
Date: 2007/6/11
Time: 13:9:3
Device ID: B108
About total Numbers: 001891
=============== ====
=============== ======
Record: 1
Event Type: 3
Year: 2007
Month: 6
Day: 7
Hour: 5
Minute: 9
Second: 37.527237
And i only want to display from Year onwards, how do i do that using fgets?
ak1dnar 1,584
Recognized Expert Top Contributor
Thanks for your help, but fgets help us to get the first line for example my text file is
Datalogs:
Date: 2007/6/11
Time: 13:9:3
Device ID: B108
About total Numbers: 001891
=============== ====
=============== ======
Record: 1
Event Type: 3
Year: 2007
Month: 6
Day: 7
Hour: 5
Minute: 9
Second: 37.527237
And i only want to display from Year onwards, how do i do that using fgets?
I didn't ask to use just only the fgets().There were number of tutorials on the search result that i supplied.
And one more thing if you want to read this values from a text file there should be a specific format for each and every record. example: -
Mike Johann | 15-02-2005 | mike@somewhere.com
-
Jessica Moore | 20-10-2000 | jess@elesewhere.com
-
-
for better readability.
The format that you have supplied also can read, but its not a god practice for creating a application. Still i can't understand whether it is a single file or a combination. and is this the only record you have?
Thanks for your help, but fgets help us to get the first line for example my text file is
Datalogs:
Date: 2007/6/11
Time: 13:9:3
Device ID: B108
About total Numbers: 001891
=============== ====
=============== ======
Record: 1
Event Type: 3
Year: 2007
Month: 6
Day: 7
Hour: 5
Minute: 9
Second: 37.527237
And i only want to display from Year onwards, how do i do that using fgets?
Use the gets function then .
I didn't ask to use just only the fgets().There were number of tutorials on the search result that i supplied.
And one more thing if you want to read this values from a text file there should be a specific format for each and every record. example: -
Mike Johann | 15-02-2005 | mike@somewhere.com
-
Jessica Moore | 20-10-2000 | jess@elesewhere.com
-
-
for better readability.
The format that you have supplied also can read, but its not a god practice for creating a application. Still i can't understand whether it is a single file or a combination. and is this the only record you have?
No i got 1891 records..= (..i am new to php that is why i am so vex now..haha
ak1dnar 1,584
Recognized Expert Top Contributor
Is this the structure of your text file or differ than this? - Datalogs:
-
Date: 2007/6/11
-
Time: 13:9:3
-
Device ID: B108
-
About total Numbers: 001891
-
===================
-
=====================
-
Record: 1
-
Event Type: 3
-
Year: 2007
-
Month: 6
-
Day: 7
-
Hour: 5
-
Minute: 9
-
Second: 37.527237
-
Record: 2
-
Event Type: 3
-
Year: 2007
-
Month: 6
-
Day: 7
-
Hour: 5
-
Minute: 9
-
Second: 37.527237
-
Record: 3
-
Event Type: 3
-
Year: 2007
-
Month: 6
-
Day: 7
-
Hour: 5
-
Minute: 9
-
Second: 37.527237
And what you meant by saying "year onwards" ?
Datalogs:
Date: 2007/6/11
Time: 13:9:3
Device ID: Data Logger
About total Numbers: 001891
=============== ====
=============== ======
Record: 1
Event Type: 3
Year: 2007
Month: 6
Day: 7
Hour: 5
Minute: 9
Second: 37.527237
Latitude: 1.342335
Longitude: 103.776921
Altitude: 0.000000
PDOP: 50.000000
HDOP: 50.000000
Satellite No: 3
Speed(KMs/hr): 0.000000
Direction: 0.000000
=============== ======
Record: 2
Event Type: 1
Year: 2007
Month: 6
Day: 7
Hour: 5
Minute: 9
Second: 42.526936
Latitude: 1.342367
Longitude: 103.776861
Altitude: 0.000000
PDOP: 50.000000
HDOP: 50.000000
Satellite No: 3
Speed(KMs/hr): 0.000000
Direction: 0.000000
=============== ======
Record: 3
Event Type: 1
Year: 2007
Month: 6
Day: 7
Hour: 5
Minute: 9
Second: 47.526634
Latitude: 1.342375
Longitude: 103.776858
Altitude: 0.000000
PDOP: 50.000000
HDOP: 50.000000
Satellite No: 3
Speed(KMs/hr): 0.000000
Direction: 0.000000
=============== ======
This is the text file, from record 1, all the way to 1891.
ak1dnar 1,584
Recognized Expert Top Contributor text.txt -
Datalogs:
-
Date: 2007/6/11
-
Time: 13:9:3
-
Device ID: Data Logger
-
About total Numbers: 001891
-
===================
-
=====================
-
Record: 1
-
Event Type: 3
-
Year: 2007
-
Month: 6
-
Day: 7
-
Hour: 5
-
Minute: 9
-
Second: 37.527237
-
Latitude: 1.342335
-
Longitude: 103.776921
-
Altitude: 0.000000
-
PDOP: 50.000000
-
HDOP: 50.000000
-
Satellite No: 3
-
Speed(KMs/hr): 0.000000
-
Direction: 0.000000
-
=====================
-
Record: 2
-
Event Type: 1
-
Year: 2007
-
Month: 6
-
Day: 7
-
Hour: 5
-
Minute: 9
-
Second: 42.526936
-
Latitude: 1.342367
-
Longitude: 103.776861
-
Altitude: 0.000000
-
PDOP: 50.000000
-
HDOP: 50.000000
-
Satellite No: 3
-
Speed(KMs/hr): 0.000000
-
Direction: 0.000000
-
=====================
-
Record: 3
-
Event Type: 1
-
Year: 2007
-
Month: 6
-
Day: 7
-
Hour: 5
-
Minute: 9
-
Second: 47.526634
-
Latitude: 1.342375
-
Longitude: 103.776858
-
Altitude: 0.000000
-
PDOP: 50.000000
-
HDOP: 50.000000
-
Satellite No: 3
-
Speed(KMs/hr): 0.000000
-
Direction: 0.000000
-
=====================
-
Try to modify this script as per your requirement. read_text.php -
<?php
-
$filename = "text.txt";
-
$fd = fopen ($filename, "r");
-
$contents = fread ($fd,filesize ($filename));
-
fclose ($fd);
-
-
$delimiter = "=====================";
-
$splitcontents = explode($delimiter, $contents);
-
-
foreach( $splitcontents as $record )
-
{
-
-
echo "$record<hr>";
-
}
-
-
?>
-
Thanks a lot, if i have anymore problem, i will pm you..= )
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Ruben |
last post by:
Hello.
I am trying to read a small text file using the readline statement. I
can only read the first 2 records from the file. It stops at the blank
lines or at lines with only spaces. I have a while statement checking
for an empty string "" which I understand represents an EOF in Python.
The text file has some blank lines with spaces and...
|
by: Garibaldi |
last post by:
Thanks to all...
I need to read a block of text, operate on the read text then move to the
next text block and so on and so on from a 650MB file.
Pseudo code would be something like this:
1. Start at the beginning of the text file
2. Read in 100K of text
3. Work with the 100K of text
|
by: G.Esmeijer |
last post by:
Friends,
I would like to read a text file (fixed length formaated) really fast and
store the data into an Access database (2003).
Using the streamreader and reading line by line, separating the line into
string just takes to long.
When I Import the file with access manually goes fast. But how to use this
fromout a C# programme
who has...
|
by: CsharpGuy |
last post by:
I have to read a text file and parse it out to load to a db and I'm having
some issues in doing it. here is what the text file looks like
Dealership number: 98665362236
Location: Maryland
Owner: John Smith
Type: Luxury
BMW, 325i, VIN12363625252362, New,, 20051212. 35400, Ocoonner
Lexus, IS300, VIN6936363633363. Used, Small dent on...
|
by: Yaniv |
last post by:
Hi
I'm new in VB.NET.
I wrote an application which opens a text file and read it all lines
untill the EOF
this file is open for read only and for sharing asllowed.
every 5 seconds another applications write another line to this file
at the end and I'm trying to read those new lines from my
applications. the problem is that the EOF...
| |
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...
|
by: ashok0866 |
last post by:
I had created a macro to read data from an excel sheet and write the
values to a text file. I had used "ActiveSheet.Range("GB" & k).Value"
command to read the values from the excel.
The issue is: some cells in the excel sheet is having two lines value
and four lines data, the text file is generating that value in a
single line. (Ex. the...
|
by: godofredo |
last post by:
Hi!
I've a weird problem using ReadAllLines Function.
I have a plain text file which has about 6500 lines, each one representing a 3D point. I read the text file and store it in a string array using ReadAllLines(). The thing is that the first time I call the function it only reads about 512 lines and stores them in the array. Second time it...
|
by: =?Utf-8?B?QnJpYW4gQ29vaw==?= |
last post by:
I want to open a text file and format it into a specific line and then apply
color to a specific location of the text and then display it in a RichTextBox
after all of this is done.
I can do all of the above after the file is loaded into the RichTextBox, and
I am trying to speed the process up by doing it in a temp file.
|
by: Keith G Hicks |
last post by:
I'm trying to read a text file and alter the contents of specific lines in
the file. I know how to use streamreader to read each line of a file. I'm
doing that already to get the data into a database. What I need help with is
on how to locate a specific line in the file, change it and then save the
updated text file. Can anyone help me out or...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
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...
|
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. ...
|
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...
|
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...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |