Modernvox Posted November 16, 2009 Share Posted November 16, 2009 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); ?> Link to comment https://forums.phpfreaks.com/topic/181740-solved-using-php-clihow-to-process-this-or-any-if-statement/ Share on other sites More sharing options...
rajivgonsalves Posted November 16, 2009 Share Posted November 16, 2009 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 Link to comment https://forums.phpfreaks.com/topic/181740-solved-using-php-clihow-to-process-this-or-any-if-statement/#findComment-958540 Share on other sites More sharing options...
Modernvox Posted November 16, 2009 Author Share Posted November 16, 2009 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? Link to comment https://forums.phpfreaks.com/topic/181740-solved-using-php-clihow-to-process-this-or-any-if-statement/#findComment-958552 Share on other sites More sharing options...
rajivgonsalves Posted November 16, 2009 Share Posted November 16, 2009 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 Link to comment https://forums.phpfreaks.com/topic/181740-solved-using-php-clihow-to-process-this-or-any-if-statement/#findComment-958557 Share on other sites More sharing options...
Modernvox Posted November 16, 2009 Author Share Posted November 16, 2009 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? Link to comment https://forums.phpfreaks.com/topic/181740-solved-using-php-clihow-to-process-this-or-any-if-statement/#findComment-958562 Share on other sites More sharing options...
rajivgonsalves Posted November 16, 2009 Share Posted November 16, 2009 this script will only work at command line, if you want it as a web page you'll have to do it in HTML and php Link to comment https://forums.phpfreaks.com/topic/181740-solved-using-php-clihow-to-process-this-or-any-if-statement/#findComment-958563 Share on other sites More sharing options...
Modernvox Posted November 16, 2009 Author Share Posted November 16, 2009 this script will only work at command line, if you want it as a web page you'll have to do it in HTML and php Great Thank You! Link to comment https://forums.phpfreaks.com/topic/181740-solved-using-php-clihow-to-process-this-or-any-if-statement/#findComment-958568 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.