why doesn't inline <?= work for me

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kevinwinters
Forum Newbie
Posts: 20
Joined: Wed Jan 06, 2010 8:31 pm

why doesn't inline <?= work for me

Post 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
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

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

Post 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.
kevinwinters
Forum Newbie
Posts: 20
Joined: Wed Jan 06, 2010 8:31 pm

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

Post by kevinwinters »

OK, thank you.
ShadowIce
Forum Commoner
Posts: 75
Joined: Tue Jan 12, 2010 8:43 am

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

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

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

Post 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..
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

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

Post 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.
Post Reply