What is the right way to make an inline HTML output variable?

I just migrated from a Ubuntu PHP workstation environment back to Windows and am using xampp. I have some code, for example:

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

that I swear to work to display a variable in a text box when I was developing earlier. But when I loaded the page in Windows / xampp, it just put that text between quotation marks in a text box. Instead, I ended up changing it to something like:

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

The latter makes sense, but I think I thought there was a reduction or something else, and I must be going crazy because I'm sure the first method worked on a difference environment.

So what is the best way to do this?

+7
html php
source share
5 answers

Save your headache and don't use short tags. They feel dirty, they do not work on every setting, and I think they can completely abandon php (this may be wrong, though).

Even if you know how to fix them, you will still be annoyed every time you have to change a new server to make them work.

Edit:. Yes, they went broke. http://cubicspot.blogspot.com/2009/06/maximum-failure-php-6-deprecates-short.html

2017 Edit: To add an important distinction, the “short echo” format <?= always on (see Dav comment below). Format <? "short open" is a separate issue. For more information, see Why are "echo" short tags that are constantly included with PHP 5.4?

+12
source share

There is a php.ini directive that controls it. Make sure you have installed:

 short_open_tag = On 
+3
source share

You probably need to include short tags on your php.ini

A better way is probably a longer <?php , since others are "not recommended." Think you can find the full Q & A right here on SO

0
source share

When executing built-in commands, a slider is not required. I personally prefer short tags, typing <?php echo old after a while.

0
source share

Yes, PHP developers do not recommend short tags because this may be against XML. There is enough time for XHTML to be thrown in favor of SG5 based HTML5. And no one used PHP to output XML anyway.

0
source share

All Articles