Assigning huge chunk of text to variable

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

    #1

    Assigning huge chunk of text to variable

    Hi there!

    I am making a web page, and I want the user to be able to decide which part of
    the webpage ends up where, left or right side. So we have what I call "content"
    and "sidebar". As in a text, you see the content to the left and the sidebar to
    the right. This is done with something like this:

    <table>
    <tr>
    <td>
    ## lots of php and html code to show the text and such
    </td>
    <td>
    ## lots of php and html code to contruct the sidebar ?>
    </td>
    </tr>
    </table>

    .... in a simplified manner. Now, the first chunk of php code is of course the
    "content" and the second is the "sidebar".

    Now, both the content and the sidebar consists of pure html and breaks into php
    code, so it's not just php code. What I would like to do is read the two
    different chunks of code into two seperate variable, much like, in pseudocode:

    <? $content = "?>
    <td>
    ## lots of php and html code to show the text and such
    </td>
    <? "; ?>

    <? $sidebar = "?>
    <td>
    ## lots of php and html code to contruct the sidebar ?>
    </td>
    <? "; ?>


    And then just do a:

    <table>
    <tr>
    $content
    $sidebar
    </tr>
    </table>

    Or reversed, depending on how the user wants to view it. It's fairly important
    to me that I don't have to output all html via php (i.e. <? print "<font
    size...>"; ?>)

    Is there a way to do this with vanilla PHP ?

    --
    Sandman[.net]
  • John Downey

    #2
    Re: Assigning huge chunk of text to variable

    Sandman wrote:[color=blue]
    > Hi there!
    >
    > I am making a web page, and I want the user to be able to decide which part of
    > the webpage ends up where, left or right side. So we have what I call "content"
    > and "sidebar". As in a text, you see the content to the left and the sidebar to
    > the right. This is done with something like this:
    >
    > <table>
    > <tr>
    > <td>
    > ## lots of php and html code to show the text and such
    > </td>
    > <td>
    > ## lots of php and html code to contruct the sidebar ?>
    > </td>
    > </tr>
    > </table>
    >
    > ... in a simplified manner. Now, the first chunk of php code is of course the
    > "content" and the second is the "sidebar".
    >
    > Now, both the content and the sidebar consists of pure html and breaks into php
    > code, so it's not just php code. What I would like to do is read the two
    > different chunks of code into two seperate variable, much like, in pseudocode:
    >
    > <? $content = "?>
    > <td>
    > ## lots of php and html code to show the text and such
    > </td>
    > <? "; ?>
    >
    > <? $sidebar = "?>
    > <td>
    > ## lots of php and html code to contruct the sidebar ?>
    > </td>
    > <? "; ?>
    >
    >
    > And then just do a:
    >
    > <table>
    > <tr>
    > $content
    > $sidebar
    > </tr>
    > </table>
    >
    > Or reversed, depending on how the user wants to view it. It's fairly important
    > to me that I don't have to output all html via php (i.e. <? print "<font
    > size...>"; ?>)
    >
    > Is there a way to do this with vanilla PHP ?
    >[/color]
    $content =<<<EOT
    Lots of things
    EOT;
    $sidebar =<<<EOT
    Some more
    EOT;

    then eval() the variables to have it parse out the php code.

    --
    John Downey




    Comment

    • Geoff Berrow

      #3
      Re: Assigning huge chunk of text to variable

      I noticed that Message-ID: <mr-77A7BA.12220422 102003@news.fu-berlin.de>
      from Sandman contained the following:
      [color=blue]
      >Is there a way to do this with vanilla PHP ?[/color]

      Lots of ways. :-)

      If you do the formatting with a stylesheet, you can simply use PHP to
      load a different stylesheet. Use sessions and that stylesheet can be
      used for all subsequent pages

      --
      Geoff Berrow
      It's only Usenet, no one dies.
      My opinions, not the committee's, mine.
      Simple RFDs http://www.ckdog.co.uk/rfdmaker/

      Comment

      • Jon Kraft

        #4
        Re: Assigning huge chunk of text to variable

        Sandman <mr@sandman.net > wrote:
        [color=blue]
        > I am making a web page, and I want the user to be able to decide which
        > part of the webpage ends up where, left or right side. So we have what I[/color]
        [snip]

        Another solution is to store content and sidebar in separate file and then
        include them approriately:

        <?php
        // decide here what comes first, if(..) blablah
        $first = "content.ph p";
        $second = "sidebar.ph p";
        ?>
        <table>
        <tr>
        <td>
        <?php include($first) ; ?>
        </td>
        <td>
        <?php include($second ); ?>
        </td>
        </tr>
        </table>

        HTH;
        JOn

        Comment

        • Sandman

          #5
          Re: Assigning huge chunk of text to variable

          In article <bn5pdg$tn4lm$1 @ID-175424.news.uni-berlin.de>,
          Jon Kraft <jon@jonux.co.u k> wrote:
          [color=blue]
          > Sandman <mr@sandman.net > wrote:
          >[color=green]
          > > I am making a web page, and I want the user to be able to decide which
          > > part of the webpage ends up where, left or right side. So we have what I[/color]
          > [snip]
          >
          > Another solution is to store content and sidebar in separate file and then
          > include them approriately:
          >
          > <?php
          > // decide here what comes first, if(..) blablah
          > $first = "content.ph p";
          > $second = "sidebar.ph p";
          > ?>
          > <table>
          > <tr>
          > <td>
          > <?php include($first) ; ?>
          > </td>
          > <td>
          > <?php include($second ); ?>
          > </td>
          > </tr>
          > </table>[/color]

          Yes, I am aware of that, but I would rather have a more flexible solution,
          where I could implement this without calling for external files. But thanks
          anyway!

          --
          Sandman[.net]

          Comment

          • Sandman

            #6
            Re: Assigning huge chunk of text to variable

            In article <titlb.153885$x x4.27516533@twi ster.neo.rr.com >,
            John Downey <blah@doesntexi st.com> wrote:
            [color=blue][color=green]
            > > Or reversed, depending on how the user wants to view it. It's fairly
            > > important
            > > to me that I don't have to output all html via php (i.e. <? print "<font
            > > size...>"; ?>)
            > >
            > > Is there a way to do this with vanilla PHP ?
            > >[/color]
            > $content =<<<EOT
            > Lots of things
            > EOT;
            > $sidebar =<<<EOT
            > Some more
            > EOT;
            >
            > then eval() the variables to have it parse out the php code.[/color]


            Yeah, that would have been great, but I am getting lots of errors when I do
            that since the "Lots of things" contain both HTML and php code intervened.

            This is the error I recieved:

            Parse error: parse error, unexpected T_ENCAPSED_AND_ WHITESPACE, expecting
            T_STRING or T_VARIABLE or T_NUM_STRING in /atlas/virtuals/texter/list.php on
            line 85

            And line 85 was a regular php code in that text:

            } elseif (! $r["kind"]){

            which seemed to mess things up.

            Perhaps my best bet is to keep it in seperate files.

            --
            Sandman[.net]

            Comment

            Working...