By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,830 Members | 2,271 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,830 IT Pros & Developers. It's quick & easy.

if NOT(condition)

P: n/a
Is there any support for a negative condition in If statements in PHP.

Some tutorials ive found say that you can use the if!(condition)cmd;
syntax. however i always get an error when i use that.

"Parse error: parse error, unexpected '!', expecting '(' in
TMP5rsqwh3ag.php on line 13"

I am runing PHP 4.3.2.

Regards
Tristan
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"Tristan" <tr************@hotmail.com> wrote in message
news:3d**************************@posting.google.c om...
Is there any support for a negative condition in If statements in PHP.

Some tutorials ive found say that you can use the if!(condition)cmd;
syntax. however i always get an error when i use that.

"Parse error: parse error, unexpected '!', expecting '(' in
TMP5rsqwh3ag.php on line 13"

I am runing PHP 4.3.2.

Regards
Tristan


<?php
$test="blah";
if(!$test=="test")print "test ain't test";
?>

remember, you need double = sign when testing this condition, or you'll end
up looking for a needle in a haystack. a single = first assigns the word
"test" to the variable and then tests the condition, resulting in a double
negative in this case.

Mich
Jul 17 '05 #2

P: n/a
Tristan wrote:
Is there any support for a negative condition in If statements in PHP.
Unlike the subject, the correct syntax is (replace NOT with !)

if (NOT condition)

Examples

if (!$done) continue;
if (!preg_match('/hello/', $text)) echo "Please say hello.";
if (!((1 <= $qty) && ($qty <= 99))) echo "Please enter 1 to 99 only.";
Some tutorials ive found say that you can use the if!(condition)cmd;
syntax. however i always get an error when i use that.


That is wrong. Please inform the authors of those tutorials they have a
syntax error in their code. Should be

if (!condition) cmd;
--
USENET would be a better place if everybody read: | to email me: use |
http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
http://www.netmeister.org/news/learn2quote2.html | header, textonly |
http://www.expita.com/nomime.html | no attachments. |
Jul 17 '05 #3

P: n/a
Danke for that. I went back to the original Tutorial and found it was
a Typo on their half which had thrown me.

"michel" <no@spam.please> wrote in message news:<cc**********@news.cistron.nl>...
"Tristan" <tr************@hotmail.com> wrote in message
news:3d**************************@posting.google.c om...
Is there any support for a negative condition in If statements in PHP.

Some tutorials ive found say that you can use the if!(condition)cmd;
syntax. however i always get an error when i use that.

"Parse error: parse error, unexpected '!', expecting '(' in
TMP5rsqwh3ag.php on line 13"

I am runing PHP 4.3.2.

Regards
Tristan


<?php
$test="blah";
if(!$test=="test")print "test ain't test";
?>

remember, you need double = sign when testing this condition, or you'll end
up looking for a needle in a haystack. a single = first assigns the word
"test" to the variable and then tests the condition, resulting in a double
negative in this case.

Mich

Jul 17 '05 #4

P: n/a
Tristan schrieb:
"Parse error: parse error, unexpected '!', expecting '(' in
TMP5rsqwh3ag.php on line 13"


simple: you wrote 'if !(...' instead of 'if (!... -- as you said, a typo.,
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.