Results 1 to 9 of 9
Thread: PHP Problem
-
07-30-2005, 04:57 PM #1Aspiring Evangelist
- Join Date
- Feb 2005
- Location
- Norway
- Posts
- 391
PHP Problem
Hi,
I have a textfile named 'log.txt'
This file's content may look something like:
How are you?
I am fine.
thanks for asking.
how are you?
So basicly its lots of lines with text, only the text are seperated by spaces.
I want each of the parts to be put into a table, so that
How
I
thanks
how
would be put into the first column named 'part1', the second part of the text in next column etc.
Its always 3 parts of text, so I only need 3 columns in the table.
fyrestrtr made the below code with some intentional error in it for me to learn but I still havent managed to fix it so therefore I ask for help..
Below is code.. thanks
PHP Code:$contents = file('log.txt');
echo '<table><tr><td>part1</td>part2</td><td>part3</td></tr>';
foreach($contents as $line)
{
$bits = explode(" ",trim($line));
if (is_array($bits))
{
echo '<tr><td>'.$bits[0].'</td>';
echo '<td>'.$bits[1].'</td>';
echo '<td>'.$bits[2].'</td></tr>';
}
}
echo '</table>';
-
07-30-2005, 06:11 PM #2Disabled
- Join Date
- Mar 2005
- Location
- North Carolina, USA
- Posts
- 174
What error are you getting?
-
07-30-2005, 06:30 PM #3Aspiring Evangelist
- Join Date
- Feb 2005
- Location
- Norway
- Posts
- 391
I dont get any error, its just that its not being sorted in the right columns in my table, but looks very messy...
Thanks for all help.
-
07-30-2005, 07:10 PM #4WHT Addict
- Join Date
- Jan 2004
- Posts
- 170
Could you post a link to the page that looks messy?
Might just be the html.
-
07-30-2005, 07:19 PM #5Aspiring Evangelist
- Join Date
- Feb 2005
- Location
- Norway
- Posts
- 391
Originally posted by fusionrays
Could you post a link to the page that looks messy?
Might just be the html.
Thanks for taking time,
heres page:
http://64.69.34.130/
EDIT:
Note Im using different output and text on this page than showed in above example.
Here its supposed to be 1st column:
Hash, 2nd: Output: and 3rd: Hex:
And the results should be printed below in the right columns.
Like all output should be printed in the Output: column, all hex should get printed in the hex: column etc.
Instead it looks pretty messy..Last edited by UrlGuy; 07-30-2005 at 07:26 PM.
-
07-30-2005, 08:19 PM #6WHT Addict
- Join Date
- Oct 2003
- Location
- Israel
- Posts
- 133
You forgot to add another <td> after part 2.
- TomerChristmas time is among us, get your loved ones Designer Fragrances
-
07-30-2005, 09:32 PM #7Aspiring Evangelist
- Join Date
- Feb 2005
- Location
- Norway
- Posts
- 391
Thanks man, didnt see that.. =P
But still its looking messy when I look at output
Its supposed to display a table.
In top theres supposed to be 3 columns.
Hash:, Output: and Hex:
below these I will put the output. So in the Output: column, all the output will go. Below the Hex:, all the hex strings will go etc.
Part of my code now looks like this:
PHP Code:$contents = file('log.txt');
echo '<table><tr><td>Hash:</td><td>Output:</td><td>Hex:</td></tr>';
foreach($contents as $line)
{
$bits = explode(" ",trim($line));
if (is_array($bits))
{
echo '<tr><td>'.$bits[0].'</td>';
echo '<td>'.$bits[1].'</td>';
echo '<td>'.$bits[2].'</td></tr>';
}
}
echo '</table>';
But still the code is looking messy, and hex isnt being displayed at all.
Also it displays for example Output: above the output, every time.. I only want it to display once.. at top, and have all output being output in the columns below it. Not have the title of the column being output all the time above the output..
You can see it at http://64.69.34.130/
Hope anyone can help me further with this.. thanks again.
-
07-31-2005, 12:30 AM #8Web Hosting Evangelist
- Join Date
- Mar 2004
- Location
- New Zealand
- Posts
- 532
Your link is broken, and there is no way that the code you posted above will repeat the header row, so I expect that's not the code you're using.
-
07-31-2005, 01:04 AM #9Web Hosting Master
- Join Date
- Jun 2003
- Location
- United States of America
- Posts
- 1,847
link didnt work for me either fyi
Computer Steroids - Full service website development solutions since 2001.
(612)234-2768 - Locally owned and operated in the Minneapolis, Minnesota area.