Check if  $input is an array and if so flatten to string so sprintf works.
Changed the debug $input to $debug_input so as to not overwrite $input.
Updated with usage.