Can u tell me this difference?

Discussion in 'PHP' started by Techmafia, Nov 22, 2010.

  1. #1
    Hey there anyone who can point me the difference between <?= and <?php
    i know both are same and work normally on web servers but when recently i had installed xampp <?= showed me loads of errors :p


    can anyone tell the difference/

    google showed nothing for just "<?=" lol :p
     
    Techmafia, Nov 22, 2010 IP
  2. ZoomRumble

    ZoomRumble Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you can use <? rather then <?php when your server have short tag enabled (short_open_tag) inside php.ini

    its shorter to type <?=$test;?> then <?php echo $test;?>

    <?= means <? echo
     
    ZoomRumble, Nov 22, 2010 IP
  3. Techmafia

    Techmafia Well-Known Member

    Messages:
    678
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #3
    Thanks for that info ZoomRumble

    just turned short_open_tag in php.ini to on and its working!!!
     
    Techmafia, Nov 22, 2010 IP
  4. ramsarvan

    ramsarvan Greenhorn

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #4
    hey, thank you.I came here while browsing and Its something useful for me.
     
    ramsarvan, Nov 23, 2010 IP
  5. xpertdev

    xpertdev Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    <?= is the short tag for to print the variable. just like echo.
    But its deprecated in newer version of PHP, so its not recommended to use. instead keep habit of using echo.

    Best of luck...
     
    xpertdev, Nov 23, 2010 IP
  6. ahmadmarafa

    ahmadmarafa Member

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #6
    there is no differance
    <?= it,s like <?php echo
     
    ahmadmarafa, Nov 23, 2010 IP
  7. SH-Karl

    SH-Karl Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I prefer using <?php to short tags, although there is no difference, I just think it's poor practise.
     
    SH-Karl, Nov 23, 2010 IP
  8. samyak

    samyak Active Member

    Messages:
    280
    Likes Received:
    7
    Best Answers:
    4
    Trophy Points:
    90
    #8
    Many hosts disable short-tags in their servers, so code that's working on your local server might generate errors on these servers. So its always better to avoid using short tags.
     
    samyak, Nov 24, 2010 IP
  9. drctaccess

    drctaccess Peon

    Messages:
    62
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #9
    I will tell you why the newer PHP versions adopted <?php instead of <?

    PHP began with <? at the start (back in version 3) which was fine at that time... but a new technology/format appeared at a later time.. called XML which guess what had the opening tag like this: <?xml

    Now.. at some point opening a xml file crashed the PHP script because of that <? so practically a xml file was interpreted as a PHP file => hence PHP decided to go with long tags to avoid any conflict with XML files.

    I hope this one helps
     
    drctaccess, Nov 26, 2010 IP