Making "containers" - is there a way?

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

    Making "containers" - is there a way?

    I want to do this:

    function square ($a){ print "-- $a --"; }

    And use it like this:

    <? square( ?> Hello! <? ) ?>

    And get this:

    -- Hello! --

    But of course it doesn't work, so I have to do this:

    function square1 { print "-- "; }
    function square2 { print " --"; }

    And us it like this:

    <? square1() ?> Hello! <? square2() ?>


    Which isn't as clean... Is there a way to solve it like I want to do it?
    If you hadn't understood it yet, it's for making a frame around blocks
    of text.
  • Martin Lucas-Smith

    #2
    Re: Making &quot;container s&quot; - is there a way?



    [color=blue]
    > it's for making a frame around blocks of text.[/color]

    Not sure exactly what you meant, but have you considered doing this in CSS
    stylesheets?


    <style type="text/css">
    p.box {border: 1px solid black; padding: 8px;}
    </style>


    <p class="box">Blo ck of text</p>



    Martin


    Comment

    • Jon Kraft

      #3
      Re: Making &quot;container s&quot; - is there a way?

      Sandman wrote:
      [color=blue]
      > If you hadn't understood it yet, it's for making a frame around blocks
      > of text.[/color]

      <p style="border-style: dashed; border-width: 1px; border-color:
      black;">Hello</p>

      HTH;
      JOn

      Comment

      • Sandman

        #4
        Re: Making &quot;container s&quot; - is there a way?

        In article <Pine.SOL.4.44. 0308261437130.1 3516-100000@green.cs i.cam.ac.uk>,
        Martin Lucas-Smith <mvl22@cam.ac.u k> wrote:
        [color=blue][color=green]
        > > it's for making a frame around blocks of text.[/color]
        >
        > Not sure exactly what you meant, but have you considered doing this in CSS
        > stylesheets?
        >
        >
        > <style type="text/css">
        > p.box {border: 1px solid black; padding: 8px;}
        > </style>
        >
        >
        > <p class="box">Blo ck of text</p>[/color]

        Thanks, but CSS only affects the appaerance, I want to actually insert things
        before and after the text.

        --
        Sandman[.net]

        Comment

        • Sandman

          #5
          Re: Making &quot;container s&quot; - is there a way?

          In article <bifrjv$fr4$1@t itan.btinternet .com>, haptiK <nospam@nospam. com>
          wrote:
          [color=blue][color=green]
          > > I want to do this:
          > >
          > > function square ($a){ print "-- $a --"; }
          > >
          > > And use it like this:
          > >
          > > <? square( ?> Hello! <? ) ?>
          > >
          > > And get this:
          > >
          > > -- Hello! --
          > >
          > > But of course it doesn't work, so I have to do this:
          > >
          > > function square1 { print "-- "; }
          > > function square2 { print " --"; }
          > >
          > > And us it like this:
          > >
          > > <? square1() ?> Hello! <? square2() ?>
          > >
          > >
          > > Which isn't as clean... Is there a way to solve it like I want to do it?
          > > If you hadn't understood it yet, it's for making a frame around blocks
          > > of text.[/color]
          >
          > whats wrong with the following...
          > <?php
          > function square($a) {
          >
          > print "-- $a --";
          >
          > }
          > ?>
          >
          > <?php square('Hello!' ); ?>
          >
          > thats all you need to do... am i missing something here?[/color]

          Well, I want to use this for things like:

          <? square( ?>
          Hello, everything here will be inside a nice looking box, constructed with a
          table, and this image will also look fine: <img ....> And bla bla bla...
          <? ); ?>

          See? I don't want to be restricted by the limitations that the function string
          implies.

          --
          Sandman[.net]

          Comment

          • André Næss

            #6
            Re: Making &quot;container s&quot; - is there a way?

            Sandman:
            [color=blue]
            > Well, I want to use this for things like:
            >
            > <? square( ?>
            > Hello, everything here will be inside a nice looking box, constructed with
            > a table, and this image will also look fine: <img ....> And bla bla bla...
            > <? ); ?>
            >
            > See? I don't want to be restricted by the limitations that the function
            > string implies.[/color]

            Use a function, but whenever the string becomes complicated use heredoc
            syntax (see
            http://www.php.net/manual/en/languag...syntax.heredoc)

            If the contents become quite large, use file inclusion where
            square('filenam e') means to wrap the contents of filename with whatever you
            define in square().

            IMO they are both a lot easier on the eye than the syntax you want... Don't
            forget that other people may have to work with your code at some stage :)

            André Næss


            Comment

            • Juha Suni

              #7
              Re: Making &quot;container s&quot; - is there a way?


              "Sandman" <mr@sandman.net > wrote in message
              news:mr-224317.22271026 082003@news.fu-berlin.de...[color=blue]
              > Well, I want to use this for things like:
              >
              > <? square( ?>
              > Hello, everything here will be inside a nice looking box, constructed with[/color]
              a[color=blue]
              > table, and this image will also look fine: <img ....> And bla bla bla...
              > <? ); ?>
              >
              > See? I don't want to be restricted by the limitations that the function[/color]
              string[color=blue]
              > implies.
              >[/color]

              How about doing it the template way ? Just insert an imaginary tag to your
              HTML, like {square}:

              {square}
              Hello, everything here will be inside a nice looking box, constructed with a
              table, and this image will also look fine: <img ....> And bla bla bla...
              {/square}

              Then at the end just pass all the output of the file through a function that
              replaces {square} and {/square} with whatever you wish. output buffering
              will be handy here, lets you edit and play with outputted text (text outside
              php tags) before it is sent to the browser.
              See: http://www.php.net/ob_start


              HTH

              --
              Suni


              Comment

              Working...