$input = trim(fgets(STDIN));
while($input)

echo $input;

これってwhileの式のところでは$inputの中が空かって判断してるの?そういう機能がついてるのか?