aa wrote:
Thanks, Roy, I felt I was missing something fundamental in PHP syntax.
Will you please explain how
if(!$line=="<?")
is interpreted by PHP as
"if $line is zero equals <?" ? I.e. if(!$line= (0=="<?"))
Where zero is implied in (!$line=="<?") ?
Putting an exclamation-mark in front of a variable like that will test
the value of the variable. I said zero, but I guess "false" would be
more appropriate. I didn't mean the number 0, but zero as in nothing,
none, null, nada - call it what you like, just be aware that PHP will
probably want to call it false ;)
if (!$test) {
do_stuff();
}
In this case, do_stuff() will be called if $test is false, meaning if
$test is not set, if it contains the value 0, if it's set to null/false,
or if it contains an empty string (e.g. '', or "" if you prefer).
if (!$test == "some string") {
do_stuff();
}
In this case, do_stuff() will be called if $test is false and equal to
"some string", which by it's very definition isn't false - "some string"
can only be false if it's "", in which case it's no longer "some
string", and there it goes around and around until we get dizzy and give
up - PHP is smarter than us, so it just says "this won't work" and moves
on. The statement will never evaluate to true, and do_stuff() will never
happen.
Basically, just keep it simple. Ask the question in plain english, and
then translate it into PHP code. If you want to ask if $a equals $b,
then ask if $a == $b. If you want to ask if $a doesn't equal $b, then
ask if $a != $b. If you want to ask if $a is false, then you can either
ask if !$a, or if $a == false.
Roy W. Andersen
--
ra at broadpark dot no /
http://roy.netgoth.org/
"Hey! What kind of party is this? There's no booze
and only one hooker!" - Bender, Futurama