#!/usr/bin/php */ /** * array of stuff. I chose a poem for the * testing, but It really can work with * anything. */ $poem = array( "Fire and Ice by Robert Frost\n", "\n", "Some say the world will end in fire,\n", "Some say in ice.\n", "From what I've tasted of desire\n", "I hold with those who favor fire.\n", "But if it had to perish twice,\n", "I think I know enough of hate\n", "To say that for destruction ice\n", "Is also great\n", "And would suffice.\n" ); /** * accepts decimals for seconds * * @param float $seconds eg. 0.1, 1.5 */ function bcsleep($seconds) { usleep(floor($seconds * 1000000)); } /** * outputs contents of array * in a typewriter style. * variable speed settings. * * @param array $array text to process * @param string $speed fast, medium, slow */ function Typewriter($array, $speed = '') { //speed setting switch($speed) { case "fast": $sec = 0.1; break; case "medium": $sec = 0.5; break; case "slow": $sec = 1; break; default: $sec = 0.1; } //data processing $length = sizeof($array); for($x = 0; $x <= $length; ++$x) { for($y = 0; $y <= strlen($array[$x]); ++$y) { ob_start(); echo $array[$x][$y]; ob_end_flush(); bcsleep($sec); } } return 0; } /** * function really only works right for the cli, * so i'm passing argv[1] as the speed argument. */ Typewriter($poem, $argv[1]); ?>