Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: <?php ?>

  1. #1
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    911
    Thanks
    302
    Thanked 2 Times in 2 Posts

    Question <?php ?>

    For some reasons my php code does not work unless i put the php keyword after the ? in my code as shows in the following example.

    Code:
    <?php
    echo "Hello";
    ?>
    The above code works



    Code:
    <?
    echo "Hello";
    ?>
    The above code does not work


    What settings do i need to do to make the second code work?

    Thanx

  • #2
    Regular Coder
    Join Date
    Oct 2006
    Location
    Bristol
    Posts
    128
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Is there a reason why you want to use <? instead of <?php ?

    AFAIK <?php is the preferred tag anyway...

    Alex
    Give me Rep if I was helpful and ignore if I wasn't ;)

    http://www.google.com <--use this before asking

    Nominate a Helpful Member


  • #3
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    911
    Thanks
    302
    Thanked 2 Times in 2 Posts
    Coz Thats a shortcut and I have seen many times people using <? instead of <?php

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,024
    Thanks
    2
    Thanked 314 Times in 306 Posts
    The short open tag <? is NOT server independent and also causes problems with xml code inside of php files. Php.net itself cautions against using it when writing portable code that will work on any server.

    Don't use it.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by cancer10 View Post
    For some reasons my php code does not work unless i put the php keyword after the ? in my code as shows in the following example.

    Code:
    <?php
    echo "Hello";
    ?>
    The above code works



    Code:
    <?
    echo "Hello";
    ?>
    The above code does not work


    What settings do i need to do to make the second code work?

    Thanx

    you need to enable short tags in php.ini

    find this short_open_tag and set it to On

    Code:
    short_open_tag = On

  • #6
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    How hard is it to type

    <?php instead of <?

    ?

    The best way is to write out the whole opening tag, and it requires almost zero extra effort.. I would stick with that!

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •