Reading from stdin is not something familiar to many php coders, so here are a few ways to read in the puzzle you are given from stdin using the PHP CLI.
$s=fgets(STDIN);
Reads in a complete line of input as a string, complete with end of line character.
$s=fgets(STDIN);Reads in a complete line of input as a string, complete with end of line character.
$c=fgetc(STDIN);Reads in a single character.
Also worth looking at are fscanf(), fgetcsv(), fread()
To test your scripts you can use this command from a linux shell (other operating systems may differ)
php your_script.php < test.txtWhere test.txt is a plain text file containing your sample input.