Results 1 to 2 of 2

Thread: <?php and variations thereof

  1. #1
    Join Date
    Apr 2012
    Location
    Central New Jersey
    Posts
    138
    Thanks
    51
    Thanked 0 Times in 0 Posts

    Default <?php and variations thereof

    The code below works (at least when error_reporting is turned off). But I do not understand WHY it works. I understand the short tag notation (and that its use is discouraged). But when I add "php" to the short tag, or remove the equal sign (use of which I do not understand), or any combination thereof, the page no longer works. I am bewildered and befuddled.

    Please help.

    PHP Code:
    <?php
    $lastUpdate 
    date'j F Y'filemtime'pageContent/test.txt' ) );
    // error_reporting( -1 );
    // ini_set( 'display_errors','On' ); 
    ?>
    <br />
    <br />
    &copy; Copyright 2006-<?= date'Y' ?>, Allan Marain, New Brunswick, NJ, All rights reserved.
    <br />
    <br />
    Page last updated <?= $lastUpdate ?>.<br />

  2. #2
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    46
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    Basically, you can make up your own mind as to whether to use them or not ( you could take a look at these:
    http://stackoverflow.com/questions/1...php-short-tags
    http://stackoverflow.com/questions/2...eptable-to-use
    http://stackoverflow.com/questions/2...fferent-in-php
    and I have no doubt that traq will proffer his own opinion on them).

    But as to your question, your code means exactly the same thing as:
    PHP Code:
    <?php 
    $lastUpdate 
    date'j F Y'filemtime'pageContent/test.txt' ) ); 
    // error_reporting( -1 ); 
    // ini_set( 'display_errors','On' );  
    ?> 
    <br /> 
    <br /> 
    &copy; Copyright 2006-<?php echo date'Y' ?>, Allan Marain, New Brunswick, NJ, All rights reserved. 
    <br /> 
    <br /> 
    Page last updated <?php echo $lastUpdate ?>.<br />
    in other words, <?= is the same as <?php echo, although it is easier to write.

    If you took out the equal sign of <?= $variable, that would be the same as just writing; <?php $variable. It doesn't not work (if that makes sense), but it just doesn't output anything.

    TL;DR: <?= means <?php echo.
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

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

    marain (12-21-2012)

Similar Threads

  1. Custom Menu (with variations) as a list?
    By madnhate in forum HTML
    Replies: 0
    Last Post: 04-06-2012, 10:26 PM

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
  •