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.