Just copy and paste the snippet into a file and save.
You need to save this under the web root, not in a web accessible folder. For example, on linux you could save it in your home directory. Say your user is "joe" then save it in /home/joe/ . Ify saved the file as interactive.php then you would invoke it via the command line with: ./interactive.php
More information is at: http://onwebdevelopment.blogspot.com/2008/03/php-interactive-shell.html