Topic: simple php question. (winxp, cli)

hi.

#!C:\php\php.exe
<?php

/* why doesn't this work on winxp?  it always goes to the default case. */

echo "\nAre you going to write some cool scripts?\n";
$name = fread(STDIN, 1024);
switch ($name) {
    case "yes":
        echo "\nHa, you can't even get this working!";
        break;
    case "no":
        echo "\nWhat are you, lazy?";
        break;
    default:
        echo "\nYes or no please.";
    }
sleep(2);
?>

thanks.

Re: simple php question. (winxp, cli)

Try doing

echo $name;

It might be adding some unwanted characters.

Re: simple php question. (winxp, cli)

hi.  echo gives no clues.  no unwanted characters.  it works if i substitute numbers but not "yes" or "no".  odd...

#!C:\php\php.exe
<?php

/* why doesn't this work on winxp?  it always goes to the default case. */

echo "\nAre you going to write some cool scripts?\n";
$name = fread(STDIN, 1024);
switch ($name) {
    case "yes":
        echo "\nHa, you can't even get this working!";
        break;
    case "no":
        echo "\nWhat are you, lazy?";
        break;
    default:
        echo "\nYes or no please.";
    }
sleep(2);
echo "\n$name";
sleep(2);
?>

Re: simple php question. (winxp, cli)

i figured it out.  there's whitespace somewhere.  trim($name) fixes it.  :s