Saturday, July 31, 2010

Basic Syntax

Basic syntax
mattsch at gmail dot com


Less is more.  The shortest and easiest way to deal with the xml tag problem assuming short tags is enabled and you don't care to listen to people who want you to always use the full php tag is this:

<?xml version="1.0" encoding="utf-8"?>

KOmaSHOOTER at gmx dot de


you also can use this kind of syntax:

if( condition ): ?>
 
else: ?>
 
endif; ?>

Tona at spikesource dot com

Jascam: Try to find more resourceful information to make your point. Your lack of ability to understand more complex concepts is not enough to diminish such a popular language as PHP. Note also that php is not replacing html but complementing it.

madman


As rosswilliams mentioned;  The example breaking in and out of the PHP tags doesn't "work as expected".  The manual and some comments mention that PHP "simply starts outputting whatever it finds..." any time a closing tag is encountered.  It would make sense to say instead - "...unless PHP is in the middle of a conditional statement; in which case it will only output the relevant block of HTML."

Some have said that using the 'echo' command is cleaner and more  efficient.  However, as the manual points out, the method of breaking out of PHP is more efficient when dealing with large sections of HTML.  Because there is less work for the parser.

Geekman at Textbook Torrents dot com

Regarding the comment by rosswilliams at advocacytechnologies dot org:

Your suspicion is correct. The following all behave exactly the same:


// output the answer by escaping
if ($true_or_false) {
   
?>
    The value of $true_or_false is true.

    } else {
   
?>
    The value of $true_or_false is false.

    }

// use echo to do the same thing - more efficient and easier to read in my opinion
if ($true_or_false) {
    echo
'The value of $true_or_false is true.';
} else {
    echo
'The value of $true_or_false is false.';
}

// use ? : operators on entire string
echo ($true_or_false) ? 'The value of $true_or_false is true.' : 'The value of $true_or_false is false.';

// use ? : operators only on the pertinent bit, to save space
echo 'The value of $true_or_false is ' . (($true_or_false) ? 'true' : 'false') . '.';

?>

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home