php script to compare value from command line

madstylex
madstylex used Ask the Experts™
on
Hi Experts,

I am writing a small php script in linux mint which is used to take an argument from the command line, compare it and confirm if it says "keyword" or not.  I am quite new to php, so it is probably something extremely simple.  I have also echoed $argv[1] in order to confirm that the script is in fact receiving the argument.

So far I have the following:

<?php

$test1 = $argv[1];

if (!$test1 == "keyword") {
        echo "you have typed in KEYWORD";
} else {
        echo "you have NOT typed in KEYWORD";
}

echo $test1;

?>

Open in new window


As this code currently stands, every single output is "you have NOT typed in KEYWORD" regardless of what I type in.

Thanks in advance
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Fixer of Problems
Most Valuable Expert 2014
Commented:
You had a '!' or Not symbol in front of $test1 on line 5 that was killing it.
<?php

$test1 = $argv[1];

if ($test1 == "keyword") {
        echo "you have typed in KEYWORD\r\n";
} else {
        echo "you have NOT typed in KEYWORD\r\n";
}

echo $test1;

?>

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial