View Single Post
Old 10-03-2007, 11:21 PM   PM User | #12
schferdi
New to the CF scene

 
Join Date: Oct 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
schferdi is an unknown quantity at this point
Outputting Data
  • echo "Hello<br/>$name"; // Works!
  • echo "Hello\n$name"; // Works!
  • echo 'Hello\n$name'; // outputs "Hello\n$name"
Why is this?
functions used with single quotes is used as direct/literal input, and text within single quotes does not get parsed.

Common Mistypes
PHP Code:
if ($variable $condition)  // will always return as true
if ($variable == $condition)  // correct usage 
PHP Code:
if ($variable !== $condition)  // enforces type comparison: http://php.net/language.operators.comparison
if ($variable != $condition)  // correct usage 
PHP Code:
fputs($fp'This is text\n'); // does not make a new line
fputs($fp"This is text\n"); // this does make a new line 
Note from Inigoesdr: While you can use any of these and/or examples, you probably want the one marked "correct". See this manual page for more info; specifically precedence.
PHP Code:
if ($variable == $condition AND $other != $condition)  // incorrect usage
if ($variable == $condition && $other != $condition)  // correct usage

if ($variable == $condition OR $other != $condition)  // incorrect usage
if ($variable == $condition || $other != $condition)  // correct usage 
PHP Code:
// Incorrect
if ($variable == $condition
      
execute(); 
      exit; 
else 
do_not_execute();
// Correct
if ($variable == $condition) {
      
execute();
      exit;
}
else 
do_not_execute(); 
More info on control structure syntax is available here.

There's also the alternative syntax for control structures available to you.

Last edited by Inigoesdr; 02-23-2008 at 02:19 PM.. Reason: Consolidating posts
schferdi is offline   Reply With Quote