Jump to content

[SOLVED] Using PHP CLI....How to process this or any if statement?


Modernvox

Recommended Posts

Wondering why my if statement is being ignored? I am using CLI

 

 <?php
fwrite(STDOUT, "Enter your name\n"); // Output - prompt user
$name = fgets(STDIN);                // Read the input
fwrite(STDOUT, "Hello $name");   
fwrite(STDOUT, "Is this an interior or exterior quote?\n");
$intorext= fgets(STDIN);
  if ($intortext== "interior") {
fwrite(STDOUT, "test");
}
exit(0);                      
?>

this

 

$intorext= fgets(STDIN);

 

should be

 

$intortext= fgets(STDIN);

 

you misspelled the variable

 

and

 

if ($intortext == "interior") fwrite(STDOUT, "Great!");

 

should be

 

if (chop($intortext) == "interior") fwrite(STDOUT, "Great!");

 

when reading from STDIN it adds a newline at the end

 

this

 

$intorext= fgets(STDIN);

 

should be

 

$intortext= fgets(STDIN);

 

you misspelled the variable

 

and

 

if ($intortext == "interior") fwrite(STDOUT, "Great!");

 

should be

 

if (chop($intortext) == "interior") fwrite(STDOUT, "Great!");

 

when reading from STDIN it adds a newline at the end

 

Works and I thank you sir. In reference to the chop function (of course i will search more on it, but) I understand it takes from the string? Does it always need to be used?

chop will have to be used when reading from STDIN I am not sure if there is any other way to avoid using it for every STDIN input you can write a function and call the function so that it returns the correct value

chop will have to be used when reading from STDIN I am not sure if there is any other way to avoid using it for every STDIN input you can write a function and call the function so that it returns the correct value

 

Ok...Will look into that. One more thing I am curious about is:

After I complete this code and implement it on a site, how will it be displayed to a user?

Will it appear as a webpage, a separate window, will it be able to be styled ie. background photo or something?

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.