Very fast php variable access in html

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

    Very fast php variable access in html

    Dear Group,

    In the past I read something, that it is possible to print out php
    variables in html very fast with a simple symtax.

    Today I came back to php documentation, but I cannot find it anymore

    Its something like

    <?php

    echo $variable ;

    ?>

    just much shorter.

    Can anybode help me ?
  • Thomas Mlynarczyk

    #2
    Re: Very fast php variable access in html

    Guenther Sohler schrieb:
    Its something like
    >
    <?php
    echo $variable ;
    ?>
    >
    just much shorter.
    <?=$variable? >

    See http://de3.php.net/echo

    But it works only if short open tags are enabled - and unless you have
    full control over the PHP config (php.ini), you cannot rely upon this.
    And even if - your code would not be portable.

    Alternatives:
    <?php o($variable) ?>
    with function o ( $variable ) { echo $variable; } or
    <?php $view->variable ?>
    with function __get ( $what ) { echo $this->$what; }

    Greetings,
    Thomas

    --
    Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
    (Coluche)

    Comment

    • Jerry Stuckle

      #3
      Re: Very fast php variable access in html

      Guenther Sohler wrote:
      Dear Group,
      >
      In the past I read something, that it is possible to print out php
      variables in html very fast with a simple symtax.
      >
      Today I came back to php documentation, but I cannot find it anymore
      >
      Its something like
      >
      <?php
      >
      echo $variable ;
      >
      ?>
      >
      just much shorter.
      >
      Can anybode help me ?
      >
      You may be thinking of <?= $variable; ?>

      But this requires short_open_tag be enabled, which can conflict with
      xml. Most hosts have it off now.

      And the difference in speed printing the variable is virtually
      unmeasurable. So it only really makes a difference to the programmer.

      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      • Thomas Mlynarczyk

        #4
        Re: Very fast php variable access in html

        Thomas Mlynarczyk schrieb:
        Alternatives:
        <?php o($variable) ?>
        with function o ( $variable ) { echo $variable; } or
        <?php $view->variable ?>
        with function __get ( $what ) { echo $this->$what; }
        Another possible solution might be the heredoc syntax:

        echo <<< EOT
        <body>
        <h1>$title</h1>
        <p>$text</p>
        </body>
        EOT;

        Greetings,
        Thomas

        --
        Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
        (Coluche)

        Comment

        • Rik Wasmus

          #5
          Re: Very fast php variable access in html

          On Sat, 17 May 2008 15:07:35 +0200, Thomas Mlynarczyk
          <thomas@mlynarc zyk-webdesign.dewro te:
          Thomas Mlynarczyk schrieb:
          >
          >Alternatives :
          ><?php o($variable) ?>
          >with function o ( $variable ) { echo $variable; } or
          ><?php $view->variable ?>
          >with function __get ( $what ) { echo $this->$what; }
          >
          Another possible solution might be the heredoc syntax:
          >
          echo <<< EOT
          <body>
          <h1>$title</h1>
          <p>$text</p>
          </body>
          EOT;
          That last one is something I definitly use often for smaller sites,
          however, your first solution seems quite useless as a simple echo would
          suffice as well. Defining obscure functions just to save typing 5
          characters every coder knows and understands does not only souns useless
          to me, as far as I am concerned I consider this very bad practise.
          --
          Rik Wasmus
          ....spamrun finished

          Comment

          • Thomas Mlynarczyk

            #6
            Re: Very fast php variable access in html

            Rik Wasmus schrieb:
            >Thomas Mlynarczyk schrieb:
            >>
            >>Alternative s:
            >><?php o($variable) ?>
            >>with function o ( $variable ) { echo $variable; } or
            >><?php $view->variable ?>
            >>with function __get ( $what ) { echo $this->$what; }
            however, your first solution seems quite useless as a simple echo would
            suffice as well. Defining obscure functions just to save typing 5
            characters every coder knows and understands does not only souns useless
            to me, as far as I am concerned I consider this very bad practise.
            True, o() is just syntactic sugar, but as the OP didn't want to use
            echo... Personally, I prefer the second variant. The disadvantage of
            using heredoc is that you cannot, e.g., loop over an array to produce
            table rows within the heredoc.

            Greetings,
            Thomas

            --
            Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
            (Coluche)

            Comment

            Working...