14

I just moved from an Ubuntu PHP workstation dev environment back to Windows and am using xampp. I have a bit of code, like so:

<input type="text" name="txtEmail" value="<?=$emailaddress;?>"/>

that I swear worked to display the variable in the textbox when I was developing before. But when I loaded the page on Windows/xampp it just put that text between the quotes in the textbox. Instead, I ended up changing it to something like:

<input type="text" name="txtFirstName" value="<?php echo($firstname);?>" />

The latter makes sense, but I guess I thought there was a shorthand or something, and I must be going crazy because I'm sure the first way was working on a difference environment.

So what's the best way to do this?

Peter Tirrell
  • 2,962
  • 4
  • 29
  • 52

5 Answers5

17

Save yourself a headache and don't use short tags. They feel dirty, they don't work on every setup, and I think they may be getting phased out of php altogether (That might be wrong though).

Even if you know how to fix them, you'll still be irritated every time you have to change your new server to make them work.

Edit: Yup, they're getting depracated. http://cubicspot.blogspot.com/2009/06/maximum-failure-php-6-deprecates-short.html

2017 Edit: To add an important distinction - the <?= "short echo" format is always enabled (see Dav's comment below). The <? "short open" format is a separate matter. For more info see Why are "echo" short tags permanently enabled as of PHP 5.4?

Community
  • 1
  • 1
Syntax Error
  • 4,475
  • 2
  • 22
  • 33
  • Ahhh, thanks, that makes sense - I knew it must be a quick answer! The short tags thing actually sounds familiar now that I think about it...my ubuntu install must have had it set by default. I'll keep that in mind in the future. – Peter Tirrell Apr 23 '10 at 02:36
  • 3
    Just in case someone wonders in here years after: the = shorthand did not get deprecated. If anything, it got promoted and from PHP 5.4 onwards is available even if short_open_tag is not enabled. Usage is still down to presonal preferrence thou. – Dav Sep 15 '16 at 08:45
3

There's a php.ini directive that controls it. Make sure yours is set to:

short_open_tag = On
Michael Mrozek
  • 169,610
  • 28
  • 168
  • 175
2

When doing inline commands the semi-colon isn't required. I personally prefer the short tags, typing <?php echo gets old after a while.

Adam Gotterer
  • 598
  • 5
  • 19
0

You probably have to enable short tags on your php.ini

The best way is probably the longer one <?php since the others are "not recommended". Think you can find a complete Q&A right here on SO

Community
  • 1
  • 1
Gonçalo Queirós
  • 1,193
  • 2
  • 9
  • 19
0

Yeah, PHP developers are deprecating short tags, because it might conflict with XML. Quite in time for XHTML getting tossed out in favour of a SGML based HTML5. And nobody was using PHP to output XML anyway..

mario
  • 1