reading "<?" from a php file

This is a discussion on reading "<?" from a php file within the PHP Language forums, part of the PHP Programming Forums category; aa wrote: > Thanks, Roy, I felt I was missing something fundamental in PHP syntax. > Will you please explain ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #11 (permalink)  
Old 01-12-2005
Roy W. Andersen
 
Posts: n/a
Default Re: reading "<?" from a php file

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
Reply With Quote
  #12 (permalink)  
Old 01-12-2005
Richards Noah \(IFR LIT MET\)
 
Posts: n/a
Default Re: reading "<?" from a php file

"aa" <aa@virgin.net> wrote in message
news:41e52d6b$0$55486$ed2619ec@ptn-nntp-reader02.plus.net...
> 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=="<?") ?
>
> "Roy W. Andersen" <roy-news@netgoth.org> wrote in message
> news:34kl59F4btrgfU1@individual.net...
> > aa wrote:
> > > Thanks for offering other options.
> > > However I would like to understand what is wrong with the one I am

> using?
> > > The litaruture does not say that fgets() is not suatable for reading
> > > characters like "<" which migh happen in any text file.

> >
> > The problem is this line:
> >
> > > if (!$line=="<?")

> >
> > You're basically saying "if $line is zero equals <?", which always fails
> > since $line isn't zero (nor would if equal <? if it ever was zero).
> >
> > Try this instead: if ($line != "<?")
> >
> > That one says "if $line isn't <?" which is exactly what you're trying to
> > say.
> >


He didn't really state that clearly. He meant "is equal to" rather than
"equals".

This:
if(!$line == "<?")

Equates to:
if( !($line) == "<?")

As the '!' has higher precedence than the '=='.

So, either use:
if($line != "<?")

Or use:
if(! ($line == "<?"))

(the former is better).

-Noah


Reply With Quote
  #13 (permalink)  
Old 01-12-2005
aa
 
Posts: n/a
Default thaks

Thank you both, now I see where my error was.


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:00 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0