Display a text file on a web page

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul

    Display a text file on a web page

    I have a text file that I am trying to display on a web page. If I cat
    or more the file it formats and displays fine. When it comes up in the
    browser it seems to loose tabs and the format gets messed up. This is
    how I display the file.

    $show = file("./fields/combined/$cdp$store");
    $arrayitems = sizeof($show);
    $x=0;
    while ($x < $arrayitems) {
    print("$show[$x]\n");
    $x++;
    }

    If I edit the file it has ^M at the end of each line if it matters.
    Does anyone have a better idea as to how to display it?
  • Ian.H

    #2
    Re: Display a text file on a web page

    On Sat, 11 Oct 2003 10:46:20 -0700, Paul wrote:
    [color=blue]
    > I have a text file that I am trying to display on a web page. If I cat or
    > more the file it formats and displays fine. When it comes up in the
    > browser it seems to loose tabs and the format gets messed up. This is how
    > I display the file.
    >
    > $show = file("./fields/combined/$cdp$store"); $arrayitems =
    > sizeof($show);
    > $x=0;
    > while ($x < $arrayitems) {
    > print("$show[$x]\n");
    > $x++;
    > }
    > }
    > If I edit the file it has ^M at the end of each line if it matters. Does
    > anyone have a better idea as to how to display it?[/color]


    <?php
    echo "<pre>\n";
    @readfile("./fields/combined/$cdp$store");
    echo "</pre>\n";
    ?>


    HTH =)



    Regards,

    Ian

    --
    Ian.H [Design & Development]
    digiServ Network - Web solutions
    www.digiserv.net | irc.digiserv.ne t | forum.digiserv. net
    Programming, Web design, development & hosting.

    Comment

    • Eric Veltman

      #3
      Re: Display a text file on a web page

      Hello Paul,

      Paul wrote:
      [color=blue]
      > I have a text file that I am trying to display on a web page. If I cat
      > or more the file it formats and displays fine. When it comes up in the
      > browser it seems to loose tabs and the format gets messed up. This is
      > how I display the file.[/color]

      A browser ignores newlines in the source when rendering HTML.
      To get a new line, you can use <BR>.

      About the tabs, browsers ignore them too.
      You could output table rows for each line in the file
      and put what's between two tabs in a table cell.
      Then the <BR> is not necessary anymore also :-)

      Best regards,

      Eric

      Comment

      • Eric Veltman

        #4
        Re: Display a text file on a web page

        Eric Veltman wrote:
        [color=blue]
        > A browser ignores newlines in the source when rendering HTML.
        > To get a new line, you can use <BR>.
        >
        > About the tabs, browsers ignore them too.
        > You could output table rows for each line in the file
        > and put what's between two tabs in a table cell.
        > Then the <BR> is not necessary anymore also :-)[/color]

        Sorry ... If the file is a free-format text file and not
        a file with fields separated by tabs, then Ian's suggestion
        is much better :-)

        Best regards,

        Eric

        Comment

        • Paul

          #5
          Re: Display a text file on a web page

          Eric Veltman <eric@[RemoveThis]veltman.nu> wrote in message news:<voge382uv rhhe7@corp.supe rnews.com>...[color=blue]
          > Eric Veltman wrote:
          >[color=green]
          > > A browser ignores newlines in the source when rendering HTML.
          > > To get a new line, you can use <BR>.
          > >
          > > About the tabs, browsers ignore them too.
          > > You could output table rows for each line in the file
          > > and put what's between two tabs in a table cell.
          > > Then the <BR> is not necessary anymore also :-)[/color]
          >
          > Sorry ... If the file is a free-format text file and not
          > a file with fields separated by tabs, then Ian's suggestion
          > is much better :-)
          >
          > Best regards,
          >
          > Eric[/color]


          Actually I don't see any message from Ian about this.
          The file is more like a free form document. What about the idea of
          maybe trying to read the file and convert Tabs to spaces before I
          display it. Does that sound possible? It would take a couple second
          longer to display but at least it would look right? I think?

          Comment

          • Easy Chen

            #6
            Re: Display a text file on a web page

            well , you can use <pre> tag to keep your format , like this:[color=blue]
            > $show = file("./fields/combined/$cdp$store");
            > $arrayitems = sizeof($show);
            > $x=0;
            > print("<pre>");[/color]
            while ($x < $arrayitems) {[color=blue]
            > print("$show[$x]\n");
            > $x++;
            > }[/color]
            print("</pre>");


            pkz505@yahoo.co m (Paul) wrote in message news:<4c2c478e. 0310110846.2faf 4a1@posting.goo gle.com>...[color=blue]
            > I have a text file that I am trying to display on a web page. If I cat
            > or more the file it formats and displays fine. When it comes up in the
            > browser it seems to loose tabs and the format gets messed up. This is
            > how I display the file.
            >
            > $show = file("./fields/combined/$cdp$store");
            > $arrayitems = sizeof($show);
            > $x=0;
            > while ($x < $arrayitems) {
            > print("$show[$x]\n");
            > $x++;
            > }
            >
            > If I edit the file it has ^M at the end of each line if it matters.
            > Does anyone have a better idea as to how to display it?[/color]

            Comment

            • Eric Veltman

              #7
              Re: Display a text file on a web page

              Hello Paul,

              Paul wrote:
              [color=blue]
              > Eric Veltman <eric@[RemoveThis]veltman.nu> wrote in message[color=green]
              >> Sorry ... If the file is a free-format text file and not
              >> a file with fields separated by tabs, then Ian's suggestion
              >> is much better :-)[/color][/color]
              [color=blue]
              > Actually I don't see any message from Ian about this.
              > The file is more like a free form document. What about the idea of
              > maybe trying to read the file and convert Tabs to spaces before I
              > display it. Does that sound possible? It would take a couple second
              > longer to display but at least it would look right? I think?[/color]

              I guess my post arrived at your news server before Ian's post did.
              Perhaps you can see Ian's post now ? Anyway, he was talking about
              using the <pre>pre-formatted text</pre> trick to let the browser
              display the pre-formatted text. That'll work too and is a lot easier.

              Converting tabs to spaces could work also, but then you have to
              choose the correct number of spaces to replace the tabs and you
              will probably want to use a non-proportional font like Courier.

              Best regards,

              Eric

              Comment

              Working...