Page 1 of 1

why doesn't inline <?= work for me

Posted: Sat Jan 16, 2010 12:30 pm
by kevinwinters
Hi,
I have been trying to use someone elses code to start learning PHP, they claim their code works fine but when I try it it does not. Basically it is trying to display a record from a MySql database that has been assigned to a variable

this does not display the date for me:

Code: Select all

 
<td align="center"><h2><font color="#009900">Sunday, <?=$SB_DATE?></font></h3></td>
 
Yet I tried to do this and it does display correctly

Code: Select all

 
 
<?php
            <td align="center"><h2><font color="#009900">Sunday, <?php
    echo $SB_DATE;
    ?></font></h3></td>
    
    ?>
 

Is there an issue with which version I am using or is it the fact I am using PHP on Windows ?


Thanks for any help

Re: why doesn't inline <?= work for me

Posted: Sat Jan 16, 2010 12:36 pm
by califdon
Even if it may work with some PHP versions and with some OS's and under some configurations of the server, you should definitely NOT start out learning PHP by using short tags. Always use full tags and commands (not =) and you will have no problems.

Re: why doesn't inline <?= work for me

Posted: Sat Jan 16, 2010 1:00 pm
by kevinwinters
OK, thank you.

Re: why doesn't inline <?= work for me

Posted: Sat Jan 16, 2010 1:25 pm
by ShadowIce
u can use short tags if u want, just open the php.ini config file in ur server's php root, and change shorttags to 1

Re: why doesn't inline <?= work for me

Posted: Sat Jan 16, 2010 1:51 pm
by John Cartwright
ShadowIce wrote:u can use short tags if u want, just open the php.ini config file in ur server's php root, and change shorttags to 1
I think your misunderstanding the point here. The point is, you do not always have access to your environment, or if you are distrubuting your code, ideally, you would want it to work across the different configurations..

Re: why doesn't inline <?= work for me

Posted: Sat Jan 16, 2010 2:25 pm
by califdon
ShadowIce wrote:u can use short tags if u want, just open the php.ini config file in ur server's php root, and change shorttags to 1
And then your script won't work on another server, or if your hosting service decides to upgrade the PHP version, ... my advice is, take the couple of milliseconds extra that it takes to enter long tags -- every time.