Search code examples
phpfopenfgetscommand-line-interfacephp-stream-wrappers

Compare string in php file and string from cli


when I get input from cli, I var_dump it and this showed for me:

    string(2) "Y
"

So how I understand I receive the single char and the bag of blank spaces, so this code will return false ($input == "Y"). How I can solve this issue?


Solution

  • You can easily remove all this whitespace using trim()

    (trim($input) == 'Y')