Results 1 to 9 of 9

Thread: PHP Problem

  1. #1
    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>'

  2. #2
    Join Date
    Mar 2005
    Location
    North Carolina, USA
    Posts
    173
    What error are you getting?

  3. #3
    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.

  4. #4
    Could you post a link to the page that looks messy?

    Might just be the html.
    Adnan.
    FusionRays.com
    Shared and Reseller Plans

  5. #5
    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.

  6. #6
    Join Date
    Oct 2003
    Location
    Israel
    Posts
    132
    You forgot to add another <td> after part 2.

    - Tomer
    Christmas time is among us, get your loved ones Designer Fragrances

  7. #7
    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.

  8. #8
    Join Date
    Mar 2004
    Location
    New Zealand
    Posts
    533
    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.

  9. #9
    Join Date
    Jun 2003
    Location
    United States of America
    Posts
    1,838
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •