473,785 Members | 2,400 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Text file Reverse reading

14 New Member
Hi,

Well, My name is Faisal, You might saw as my ID. I got into php before a few months...

I need help.. I am trying to read a file that is .txt format..
Line by Line, Reverse action..

I mean from Last to 1st line.. I really don't care.. I can write them on my memory of php.. No matter..

Can you advice me how can I do this work?

I mean if i can do from an array.. So can you guide me how? I am not so good in arrays ;)

Help please...

Waiting for answer!

FAISAL!
Mar 22 '08
14 3547
ronverdonk
4,258 Recognized Expert Specialist
As I see it, your text file (,txt) does not contain any newline's (\n) or carriage return chars (\r) or a combination of these.

A 'normal' text file has this at the end of each line, so when you read it in the end of each text line can be found and so the text file can be split in different lines.

Since you (as I image) do not have that, then you must determine what is the end (or beginning) of each new shoutbox entry text line. Knowing that you can spolit it up in different text lines and sort it, newest on top.

So questions are: (a) why does you text line not have an end (newline, carriage return or both) and (b) how else can we determine the beginning or end of a text line.

Ronald
Mar 23 '08 #11
Faisal Shah
14 New Member
As I see it, your text file (,txt) does not contain any newline's (\n) or carriage return chars (\r) or a combination of these.

A 'normal' text file has this at the end of each line, so when you read it in the end of each text line can be found and so the text file can be split in different lines.

Since you (as I image) do not have that, then you must determine what is the end (or beginning) of each new shoutbox entry text line. Knowing that you can spolit it up in different text lines and sort it, newest on top.

So questions are: (a) why does you text line not have an end (newline, carriage return or both) and (b) how else can we determine the beginning or end of a text line.

Ronald
Well, Again.. It's my first time to make a shoutbox :)

Well, can you please have a look on my shoutbox.php code here???

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. //Fsoft ShoutBox 1.0 Faisal Shah's Edition
  4. //Faisal Shah => 2:48PM 22 March 2008 French Standard time (+1GMT)
  5. //(c)Fsoft Software Development (Shout Box) 2008 All Rights Reserved.
  6.  
  7. $dbname = "shoutboxdb.txt";
  8. $name = $_POST["name"];
  9. $web_site = $_POST["web_site"];
  10. $email = $_POST["email"];
  11. $message = $_POST["message"];
  12. $date = date('m/d/Y H:i:s');
  13. $ip = $_SERVER['REMOTE_ADDR'];
  14. $ip_final = "$ip";
  15. $send = $_POST["send"];
  16. $new_line = "<br>..............";
  17. $full_message = "<br><a target=\"blank\" href=\"http://$web_site\">$name</a>  $email  <a target=\"blank\" href=\"http://whois.domaintools.com/$ip_final\"> $date</a> <br> <b>$message</b>";
  18.  
  19. if($send == Shout){
  20. if($name == "")
  21. {
  22. echo "Please insert valid name";
  23. @include('form.html');
  24. }elseif($message == "")
  25. {
  26. echo "Please insert message into message field..";
  27. @include('form.html');
  28. }else
  29. {
  30.  
  31. $f_handle = fopen($dbname,'a');
  32. fwrite($f_handle,$full_message.$new_line);
  33. fclose($f_handle);
  34.  
  35. echo "<i>Message Sent....</i>";
  36. @include('form.html');
  37. }
  38. }else
  39. {
  40. @include('form.html');
  41. }
  42. ?>
  43.  
Can you please finally fix that \n thing for new line??

Thanks..It will help me to finish this shoutbox and to learn as well ;)

FAISAL!
Mar 23 '08 #12
ronverdonk
4,258 Recognized Expert Specialist
Since you do not write the newline, write it to your output text file like this[php]fwrite($f_handl e,$full_message .$new_line."\n" );[/php]Then you can read the file as I showed earlier.

Ronald
Mar 23 '08 #13
Faisal Shah
14 New Member
Since you do not write the newline, write it to your output text file like this[php]fwrite($f_handl e,$full_message .$new_line."\n" );[/php]Then you can read the file as I showed earlier.

Ronald
Thanks Mr. Ronald.. It worked.. If I will have any other problem.. I will come here ;)

Thanks a Lot...

FAISAL!
Mar 23 '08 #14
ronverdonk
4,258 Recognized Expert Specialist
You are welcome. We'll see you around some time.

Ronald
Mar 23 '08 #15

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

Similar topics

5
14918
by: xEM | last post by:
how can i read for example 10 last lines from a text file beginning from last line? do you have some idea? in a different manner... how can i set file position indicator one line upper in text file (line ends with "\n") ? -- pozdr. xEM~
14
13733
by: Erik Andersson | last post by:
Hi! I need to read a file (line-by-line) in reverse order, without reading the whole file into memory first. Is there an easy way of doing this? As in, is there a PHP function I could use? The solution has to be platform independent, so "popen("tac $filename")... wouldn't work.
7
17463
by: Jay | last post by:
I have a very large text file (being read by a CGI script on a web server), and I get memory errors when I try to read the whole file into a list of strings. The problem is, I want to read the file backwards, starting with the last line. Previously, I did: myfile = open('myfile.txt', 'r') mylines = myfile.readlines() myfile.close()
20
33075
by: sahukar praveen | last post by:
Hello, I have a question. I try to print a ascii file in reverse order( bottom-top). Here is the logic. 1. Go to the botton of the file fseek(). move one character back to avoid the EOF. 2. From here read a character, print it, move the file pointer (FILE*) to 2 steps back (using fseek(fp, -2, SEEK_CUR)) to read the previous character. This seems to be ok if the file has a single line (i.e. no new line character). The above logic...
4
7260
by: Jeff Rodriguez | last post by:
How would one go about reading a file line by line in reverse? For Example: -- FILE -- 1 2 3 4 5 -- FILE --
6
6372
by: Rajorshi Biswas | last post by:
Hi folks, Suppose I have a large (1 GB) text file which I want to read in reverse. The number of characters I want to read at a time is insignificant. I'm confused as to how best to do it. Upon browsing through this group and other sources on the web, it seems that there are many ways to do it. Some suggest that simply fseek'ing to 8K bytes before the end of file, and going backwards is the way. In this case, am I guaranteed best results...
6
44119
by: Neil Patel | last post by:
I have a log file that puts the most recent record at the bottom of the file. Each line is delimited by a \r\n Does anyone know how to seek to the end of the file and start reading backwards?
4
3590
by: Stupid48 | last post by:
I'm trying to do a simple task but can't seem to find a solution. How do I read lines from a text file backwards. i.e. I want to select the last 20 lines of a text file and display them in order starting with the last line first..... Any assistance would be greatly appreciated.... Thanks, Chris
2
1642
by: RobcPettit | last post by:
Hi, I have software that records betfair data into a csv file. I have no access to the code, al I can adjust is the intervals at which it records, 1sec up, and which folder/file to save the data to. Ive written some code myself which uses streemreader to read the file into an array, which I then reverse as I only want the last 10-15 lines entered in the file. I fire this code using a timer. My problem is this: If the betfair software is...
11
4219
by: JWest46088 | last post by:
I'm having difficulty trying to figure out how to print a text file from a hash table one line at a time. I have the text file read into the hash table and can print the text file all at once, but I can't seem to figure out how to do it one line at a time. Here is what I'm trying to do: I want the user to be able to print the text file one line at a time by clicking a button to see the next line. Example: If text_file1 first line is...
0
9646
marktang
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10346
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
10157
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...
1
7504
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
6742
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
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
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
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.