<?= $some_var_or_other ?> ... <?php echo $some_var_or_other ?>

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

    <?= $some_var_or_other ?> ... <?php echo $some_var_or_other ?>

    Hi...

    I seem to remember reading somewhere about the proper way of doing this sort
    of thing in the middle of some html, for example:

    <a href="<?= $some_url_or_ot her ?>">Click this!</a>

    What is the most proper way of doing such? Would it be to do the full
    monty?:

    <a href="<?php echo $some_url_or_ot her ?>">Click this!</a>

    I am writing my output to be xhtml strict compliant, so I guess for
    continuity alone it should be the latter, but are there any specific reasons
    for using the long-winded way? I'd like to know people's thoughts...

    HYCSSLOTS...


    Plankmeister.


  • E-Star

    #2
    Re: &lt;?= $some_var_or_ot her ?&gt; ... &lt;?php echo $some_var_or_ot her ?&gt;

    In article <3f41d39e$0$324 54$edfadb0f@dre ad16.news.tele. dk>, The
    Plankmeister <plankmeister_N O_@_SPAM_hotmai l.com> wrote:
    [color=blue]
    > <a href="<?php echo $some_url_or_ot her ?>">Click this!</a>[/color]

    Use this one.

    Comment

    • Ian.H [dS]

      #3
      Re: &lt;?= $some_var_or_ot her ?&gt; ... &lt;?php echo $some_var_or_ot her ?&gt;

      On Tue, 19 Aug 2003 02:16:13 -0600 in
      <message-id:190820030216 135042%unix_cor e@linuxmail.org >
      E-Star <unix_core@linu xmail.org> wrote:
      [color=blue]
      > In article <3f41d39e$0$324 54$edfadb0f@dre ad16.news.tele. dk>, The
      > Plankmeister <plankmeister_N O_@_SPAM_hotmai l.com> wrote:
      >[color=green]
      > > <a href="<?php echo $some_url_or_ot her ?>">Click this!</a>[/color]
      >
      > Use this one.[/color]


      .... and to explain why to the OP...

      <? ?> can be used if shorttags is enabled in php.ini but this isn't
      always the case for every server and I suspect becoming less and less
      the case as more and more people use XML for various tasks. XML uses
      <?xml as it's tag, and causes confusion with PHP, so it's always
      advisable (IMO at least) to use the <?php rather than <? (extending to
      the echo <?php echo rather than <?= too).


      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

      • Jochen Buennagel

        #4
        Re: &lt;?= $some_var_or_ot her ?&gt; ... &lt;?php echo $some_var_or_ot her ?&gt;

        Ian.H [dS] wrote:
        [color=blue]
        > <? ?> can be used if shorttags is enabled in php.ini but this isn't
        > always the case for every server and I suspect becoming less and less
        > the case as more and more people use XML for various tasks. XML uses
        > <?xml as it's tag, and causes confusion with PHP, so it's always
        > advisable (IMO at least) to use the <?php rather than <? (extending to
        > the echo <?php echo rather than <?= too).[/color]

        shorttags off has the advantage that you can use "<?xml" directly in
        your files (i.e. without having to "print()" or "echo()" it), but if you
        do that, you lose the ability to run your script on a server that has
        shorttags on. If you're going to run only on servers who's php.ini you
        control, that's no problem, but the default is still shorttags=on, so
        that is what most hosters use.

        So, if you're coding for the general public, shorttags=on is more
        common, but you can't rely on it, so it is safer to use "<?php echo...".
        But you can't rely on shorttags=off either, so for xhtml compliant files
        you should use <?php echo "<?xml...." ;?>

        Jochen

        --
        /**
        * @author Jochen Buennagel <zang at buennagel dot com>
        * @see http://www.sourceforge.net/projects/zang
        */

        Comment

        • DvDmanDT

          #5
          Re: &lt;?= $some_var_or_ot her ?&gt; ... &lt;?php echo $some_var_or_ot her ?&gt;

          XHTML doesn't really care which version you use... The absolute best way
          anyway seems to be <?PHP echo $url;?> Notice the ;... Doesn't matter though,
          just that it seems better as chances are you might feel like extending that
          piece of code and forget to att the ; at that point...

          --
          // DvDmanDT
          MSN: dvdmandt@hotmai l.com
          Mail: dvdmandt@telia. com
          "The Plankmeister" <plankmeister_N O_@_SPAM_hotmai l.com> skrev i meddelandet
          news:3f41d39e$0 $32454$edfadb0f @dread16.news.t ele.dk...[color=blue]
          > Hi...
          >
          > I seem to remember reading somewhere about the proper way of doing this[/color]
          sort[color=blue]
          > of thing in the middle of some html, for example:
          >
          > <a href="<?= $some_url_or_ot her ?>">Click this!</a>
          >
          > What is the most proper way of doing such? Would it be to do the full
          > monty?:
          >
          > <a href="<?php echo $some_url_or_ot her ?>">Click this!</a>
          >
          > I am writing my output to be xhtml strict compliant, so I guess for
          > continuity alone it should be the latter, but are there any specific[/color]
          reasons[color=blue]
          > for using the long-winded way? I'd like to know people's thoughts...
          >
          > HYCSSLOTS...
          >
          >
          > Plankmeister.
          >
          >[/color]


          Comment

          • R. Rajesh Jeba Anbiah

            #6
            Re: &lt;?= $some_var_or_ot her ?&gt; ... &lt;?php echo $some_var_or_ot her ?&gt;

            "The Plankmeister" <plankmeister_N O_@_SPAM_hotmai l.com> wrote in message news:<3f41d39e$ 0$32454$edfadb0 f@dread16.news. tele.dk>...[color=blue]
            > Hi...
            >
            > I seem to remember reading somewhere about the proper way of doing this sort
            > of thing in the middle of some html, for example:
            >
            > <a href="<?= $some_url_or_ot her ?>">Click this!</a>
            >
            > What is the most proper way of doing such? Would it be to do the full
            > monty?:
            >
            > <a href="<?php echo $some_url_or_ot her ?>">Click this!</a>[/color]

            I prefer short tag <?=$foo?> 'cos it's IMO quite fast. Also, I
            hate echo and would prefer to write PHP code without the use of echo.

            (Many thanks to Rasmus for fighting on behalf of short tags:))

            Comment

            • Robert Hennig

              #7
              Re: &lt;?= $some_var_or_ot her ?&gt; ... &lt;?php echo $some_var_or_ot her ?&gt;

              Jochen Buennagel wrote:
              [color=blue]
              > Ian.H [dS] wrote:
              >[color=green]
              >> <? ?> can be used if shorttags is enabled in php.ini but this isn't
              >> always the case for every server and I suspect becoming less and less
              >> the case as more and more people use XML for various tasks. XML uses
              >> <?xml as it's tag, and causes confusion with PHP, so it's always
              >> advisable (IMO at least) to use the <?php rather than <? (extending to
              >> the echo <?php echo rather than <?= too).[/color]
              >
              >
              > shorttags off has the advantage that you can use "<?xml" directly in
              > your files (i.e. without having to "print()" or "echo()" it), but if you
              > do that, you lose the ability to run your script on a server that has
              > shorttags on. If you're going to run only on servers who's php.ini you
              > control, that's no problem, but the default is still shorttags=on, so
              > that is what most hosters use.
              >
              > So, if you're coding for the general public, shorttags=on is more
              > common, but you can't rely on it, so it is safer to use "<?php echo...".
              > But you can't rely on shorttags=off either, so for xhtml compliant files
              > you should use <?php echo "<?xml...." ;?>
              >
              > Jochen
              >[/color]
              Or use:
              if(ini_get('sho rt_open_tag') == 'on') {
              [code to be executed if shorttag is enabled]
              }
              else {
              [code to be excecuted with shorttag disabled]
              }

              Robert

              Comment

              Working...