Original code (works in web server):
Modified code (works in command line):
Some snippets adapted from documentation
provided by The PHP Documentation Group.
The PHP manual text and comments
are covered by the Creative Commons Attribution 3.0 License,
copyright (c) the PHP Documentation Group.
The original snippet is here: