I want to display the contents of a particular log file (simple text file, I mean in Linux). But there is a problem: The contents need to be organized in a fixed format. Have a look at this log file:
sampleLog.txt
[text]User Name: XYZ
Reported Problems Description: Blah! Blah! Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!
Remarks: None[/text]
So, while displaying the contents of above file on a web page, I want to format the field names found in the log file: User Name:, Reported Problems Description:, and Remarks:. These fields may contain a variable length of text and no specific line number is assumed for them to appear on.
Any ideas?
The desired output should look like this:
User Name: XYZ
Reported Problems Description: Blah! Blah! Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!
Remarks: None
Formatting Fields and Text Being Displayed from Text File
Moderator: General Moderators
Re: Formatting Fields and Text Being Displayed from Text Fil
The format in the written file is as it has been written in to it like:
The output in the file will look like this:
Date: 09-02-2011
User name: testuser
Description: Lorem ipsum dolor sit amet, consectetur adipisici elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
--------------------------------------------------------------------
I guess any more formatting than that would mean implementing something like a text processing script.
Code: Select all
<?php
//creating a view variables
$test = "Lorem ipsum dolor sit amet, consectetur adipisici elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
$time = date("d-m-Y");
$username = "testuser";
//opening the file to write to
$handle = fopen("test.log", "a+");
//creating the message which is written to file as seen.
$msg = "
Date: $time
User name: $username
Description: $test
--------------------------------------------------------------------";
//writing and closing the file
fwrite($handle, $msg);
fclose($handle);
?>
Date: 09-02-2011
User name: testuser
Description: Lorem ipsum dolor sit amet, consectetur adipisici elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
--------------------------------------------------------------------
I guess any more formatting than that would mean implementing something like a text processing script.
Re: Formatting Fields and Text Being Displayed from Text Fil
divedj wrote:The format in the written file is as it has been written in to it like:
The output in the file will look like this:Code: Select all
<?php //creating a view variables $test = "Lorem ipsum dolor sit amet, consectetur adipisici elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; $time = date("d-m-Y"); $username = "testuser"; //opening the file to write to $handle = fopen("test.log", "a+"); //creating the message which is written to file as seen. $msg = " Date: $time User name: $username Description: $test --------------------------------------------------------------------"; //writing and closing the file fwrite($handle, $msg); fclose($handle); ?>
Date: 09-02-2011
User name: testuser
Description: Lorem ipsum dolor sit amet, consectetur adipisici elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
--------------------------------------------------------------------
I guess any more formatting than that would mean implementing something like a text processing script.
Guru, that is how I am already writing / creating log files! Now, let's go one step further:
Display the same text from the file you created in your example. But the output on the page should be such that the filed names (User Name, Date, Description, etc.) are displayed in bold face. And we do not want to change the original log file you created in your example.
-
sirholiday
- Forum Newbie
- Posts: 7
- Joined: Wed Aug 15, 2007 8:41 am