Skip to content

Instantly share code, notes, and snippets.

@surferxo3
Last active April 28, 2017 12:17
Show Gist options
  • Save surferxo3/572510ba1fd3e4c1c3738cba28784bd6 to your computer and use it in GitHub Desktop.
Save surferxo3/572510ba1fd3e4c1c3738cba28784bd6 to your computer and use it in GitHub Desktop.
Runtime message output for error logging and monitoring with support for different OS platforms.
<?php
/*#############################
* Developer: Mohammad Sharaf Ali
* Designation: Web Developer
* Version: 1.0
*/#############################
// HELPER METHODS
function br2nl($str) {
return preg_replace('#<br\s*?/?>#i', PHP_EOL, $str);
}
function toScreen($data, $exit = false) {
$isCli = !empty($_REQUEST['curl']) || substr(PHP_SAPI, 0, 3) === 'cli' ? true : false;
ob_implicit_flush(true);
// if html is there in $data then use array_map('htmlentities', $data)
if (is_object($data) || is_array($data)) {
echo ($isCli ? print_r($data, true) : '<pre>' . print_r($data, true) . '</pre>') ;
} else {
echo ($isCli ? br2nl($data) . PHP_EOL : nl2br($data, true) . '<br />' );
}
ob_get_level() > 0 ? ob_flush() : flush();
ob_implicit_flush(false);
if ($exit) {
exit;
}
}
// MAIN
for ($i = 1; $i <= 10; $i++) {
toScreen('10 x ' . $i . ' = ' . (10 * $i) . '<br />');
sleep(2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment