Results 1 to 3 of 3

Thread: Need help in understanding a code

  1. #1
    Join Date
    Mar 2009
    Location
    Chennai, India
    Posts
    77
    Thanks
    16
    Thanked 7 Times in 6 Posts

    Default Need help in understanding a code

    Hi, I have some source code downloaded and planning to use it in my site. I came across a function and I need a small clarification

    Here is the code:
    Code:
    <?php
     // function for showing an error message in a table
     function errormess($hiba){
     ?>  
     	 <table width=100% align=center bgcolor=#CCCCCC cellspacing=1 cellpadding=3>
    	 <tr><td bgcolor=#CCCCCC><b>The following error(s) found:</b></td></tr>
    	 <tr><td bgcolor=#FFFFFF align=center><?=$hiba?></td></tr></table>
    
     <?php
     }
    In
    Code:
    <?=$hiba?>
    , i see that an equal sign is placed before the variable $hiba. What is this? Does is work like
    Code:
    echo $hiba;
    Anyway, I tried to place an = sign before a variable name and placed in a php page and it doesn't work. So, can you pls tell me what
    Code:
    <?=$hiba?>
    is doing?

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    It works like echo. Its only for short tags, and you can't do it in the middle of a php code, for example.

    Can't:
    PHP Code:
    <?php
    $var 
    "hello";
    =
    $var;
    ?>
    Can:
    PHP Code:
    <?php
    $var 
    "hello";
    ?>

    <?=$var?>
    Jeremy | jfein.net

  3. The Following User Says Thank You to Nile For This Useful Post:

    borris83 (03-30-2009)

  4. #3
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    This way of doing it is not always recommended though, 90% of the time it's great and works just as you'd expect it to but just like short tags in general, <? ?> sometimes won't work for certain servers and to be absolutely sure it will work no matter what the platform you should use <?php echo $var ?>.

  5. The Following User Says Thank You to Schmoopy For This Useful Post:

    borris83 (03-30-2009)

Bookmarks

Posting Permissions

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